View Full Version : Setting values due to value in option group


Graham T
11-27-2001, 05:50 AM
I would like to set the values of various controls to N/A if the value chosen in an option group is set to No.

I can do this using the following code for setting the value of one combo box and would like to know if other controls can be added to the one line of code:

Private Sub grpOptions_AfterUpdate()

If (Me!grpOptions = 2) Then 'Option 2 = "No"
Me!cboAltHome2ID = 5 'Value 5 = "N/A" in the table.
Else
Me!cboAltHome2ID = "" 'If option group value = 1 or Yes_
'then value of combo box is left blank.

End If

End Sub

[This message has been edited by Graham T (edited 11-27-2001).]

Harry
11-27-2001, 05:57 AM
Yes you can put as many lines of code in between If, Else and End if.

Jack Cowley
11-27-2001, 06:01 AM
I am not quite sure what you mean by "...if other controls can be added to the one line of code..." but here is my guess...

Private Sub grpOptions_AfterUpdate()

Select Case grpOptions

Case 1
Me!cboAltHome2ID = ""
Set other fields if you need to

Case 2
Me!cboAltHome2ID = 5
Set other fields if you need to

End Select

End Sub

Graham T
11-27-2001, 06:25 AM
Sorry, didn't explain very well. Where I would like to set other controls with a value of N/A in the first IF statement as such;

If (Me!grpOptions = 2) Then 'Option 2 = "No"
Me!cboAltHome2ID = 5 and [OtherFields] = N/A (can this part be done?)