Click to See Complete Forum and Search --> : Binding option buttons to data


Tim Allman
November 24th, 1998, 11:24 AM
I have a form with bound controls to a data source.

The text and list controls work ok but I can't seem to

get the option button to update when I change records.

What it the best way to update the option buttons and

check marks when changing to a new record.

Thanks for any replies.

Crazy D
November 25th, 1998, 02:16 AM
As far as I know, you cannot bound datacontrols to option buttons.

You could write one your own (with VB 5 / 6).

Or write a wrapper function, which reads the datafield, and depending on that value set an option-button on or off.


Hope it helps


Crazy D

James Grant
November 27th, 1998, 11:19 AM
Tim-


The best way I have found is to bind the field to a HIDDEN text box, and use events to tie it to a checkbox.


For example:



'' Triggered by user action

Private Sub Check1_Click()

'' Use 1 for checked, 0 for unchecked

If (Check1.Value = vbChecked) Then

Text1.Text = "1"

Else

Text1.Text = "0"

End If

End Sub


'' Triggered by record refresh

Private Sub Text1_Change()

If (Text1.Text = "1") Then

Check1.Value = vbChecked

Else

Check1.Value = vbUnchecked

End If

End Sub




You may think that this would cause an endless loop, but VB stops firing events if the data doesn't change.


This also allows you to make a "Y/N" (character) field into a checkbox.


-Jim