Option Group using IF, Then, Else

Graham T

Registered User.
Local time
Today, 13:13
Joined
Mar 14, 2001
Messages
300
I am trying to set values within a combo box to N/A dependant on a value choosen from an option group on my form. If a user selects a value then various controls should be set to N/A as they require no further details to be entered.

The code I have tried using is as follows:

******************************************

Private Sub Alt_Acc_1_AfterUpdate()

'Code attached to option group where 'Yes' = 1
'and 'No' = 2

If (Me!Alt_Acc_1 = 1) Then 'equals Yes
Me!Alt_HomeID = "" 'leave both combo boxes blank
Me!Pref_Tenure_id = ""

Else
Me!Alt_HomeID = 5 'set both combo boxes to N/A
Me!Pref_Tenure_id = 5

End If

End Sub

******************************************

Is this possible as at present the only value being set is Alt_HomeID to N/A. These values are both stored in seperate tables with the ID of 5.

I hope this makes sense.

Graham



[This message has been edited by Graham T (edited 12-19-2001).]
 
How about simplifying this a bit.

For this example, make sure you're using an OPTION GROUP as opposed to just individual option buttons.

For this example the names are:
Option Group named: optSelect
Controls to set: cmbCombo1 cmbCombo2, etc.

Private Sub MyExample()
' code to set based on option selection
Select Case optSelect
Case 1
' if the first option is selected
cmbCombo1.Enabled = False
cmbCombo2.Enabled = True

Case 2
' if the second option is selected
cmbCombo1.Enabled = True
cmbCombo2.Enabled = False

Case Else
' if any option other than 1 or 2 are selected
cmbCombo1.Enabled = False
cmbCombo2.Enabled = False

End Select
End Sub


If you have further questions, feel free to email me.

Bob Larson
mailto:accessbob@hotmail.com

[This message has been edited by boblarson (edited 12-19-2001).]
 
Thanks for the reply Bob

However using the Select Case option, I am still struggling to set the values of the combo boxes to N/A (value of 5).

The code below will set the first control (Alt_HomeID)to N/A but no the further control.

*****************************************

Select Case Alt_Acc_1

Case 1
' if the first option is selected (option 1 = 'Yes')
Me!Alt_HomeID = ""
Me!Pref_Tenure_id = ""

Case 2
' if the second option is selected
Me!Alt_HomeID = 5
Me!Pref_Tenure_id = 5

End Select

End Sub

*****************************************

I wonder if you could throw any further light on this.
 
Yes, you have to set the VALUE of the combo box. In other words: Alt_HomeID.Value = ""

You don't need to include " Me! "

Since you're setting it from the form module and not an external module the Me! is implied and not required.

BL
hth

[This message has been edited by boblarson (edited 12-20-2001).]
 
Sorry Bob

Sorted it now.

It was somebody elses assignment that they had mailed me and one of the control names contained a space that I had not noticed.

If, Then, Else will now update the fields required.

Thanks for your assistance.
 

Users who are viewing this thread

Back
Top Bottom