Discussion Locked

Visual Basic 6 Checkbox control

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I want to use a checkbox control to enter boolean selection in a database. I can do this, but there are a few issues that only occur when the checkbox control is bound to a datasource.

1) The checkbox appears grayed with a check, even when the value should evaluate to unchecked. When a checkmark is then indicated, the checkbox has a white background and the check is clearer.
The grayed appearance is undesirable and misleading

2) This happens only when the checkbox is bound to a datasource: If there is code in the checkbox click event (e.g. to evaluate whether the checkbox = vbchecked) the code will execute after the form initialize event and before the form load event. This can cause big problems, because I only want the code toexecute when the checkbox is checked.

Does anyone know ways to work around these problems?

5 replies

by burtsa

If I remember the settings correctly the checkbox has 3 settings 0 - unchecked, 1 - checked, 2-null. Now a boolean field in a datasource has 3 values 0 - false, -1 - true, Null - Null. You need to do some kind on converion. What I did was put a small routine the the Recordset_Move_Completed event to convert the field value to the checkbox.

Note: if this will be a data-entry form then you need to do something similar in the WillChangeRecord event.

Shawn

by mikedale

What I do is instead of using a Boolean field in the Database, I use a byte field and store the numbers 0 and 1.

To stop the check box code from executing when the form is loading, I declare a Form Load variable (whatever you whan to call it) andset it to 0. Then place a timer control on the form with the interval set to around 100. The timer will start timing after the form has loaded, and sets the Form Loaded variable to 1.

In the check box event place your code inside a If statment or Select Case statement so that the code only executes when the form is loaded (form loaded variable is 1) and not when the form is loading.

Hope this helps
Mike Dale

This discussion is closed to new replies.