If/ElseIF/Else ?

AN60

Registered User.
Local time
Today, 18:59
Joined
Oct 25, 2003
Messages
283
I have been using the following in AfterUpdate event of "MyField1". This has worked ok enabling and disabling one field which in this case is named Myfield2. Now I want to enable and disable multiple fields based on text content of "MyField1" and am not sure what to do. MyField1 is a combo. I've searched about but can't find anything to point me in the right direction. Any suggestions?

If Me.Myfield1 = "mytext" Then
Me.Myfield2.Enabled = True
ElseIf Me.Myfield1 = "someothertext" Then
Me.myfield2.Enabled = True
Else
Me.myfield2.Enabled = False
End If
End Sub
 
A Select Case structure in the AfterUpdate event of the ComboBox should do it:

Code:
Select Case Me.MyField1
  Case "mytext"
      Me.Myfield2.Enabled = True
      '-- And anything else you want to do
  Case "someothertext"
      Me.myfield2.Enabled = True
      '-- And anything else you want to do
  Case Else
     Me.myfield2.Enabled = False
      '-- And anything else you want to do
End Select
 
RuralGuy.
Thanks for your suggestion.
I just tried your method and achieved the same result as my effort above. I still can't enable or disable more than one field based on the text that is in MyField1. I need to enable/disable at least two new fields, MyField3 & MyField4 as well as the original Myfield2 using the text in Myfield1. When I add references to the two new fields I get an error. Am I missing something?
 
This method *will* work:
Code:
Select Case Me.MyField1
  Case "mytext"
      Me.Myfield2.Enabled = True
      Me.Myfield3.Enabled = True
      Me.Myfield4.Enabled = True
      '-- And anything else you want to do
  Case "someothertext"
      Me.myfield2.Enabled = True
      Me.Myfield3.Enabled = True
      Me.Myfield4.Enabled = True
      '-- And anything else you want to do
  Case Else
     Me.myfield2.Enabled = False
     Me.Myfield3.Enabled = False
     Me.Myfield4.Enabled = False
     '-- And anything else you want to do
End Select
What error are you getting?
 
RuralGuy
Thank you once again. I had edited the code to reflect what you had and it was still not working until I dug a little deeper. I have a combo called combo7 but in the combo's field view it says batch3. I can't remember how it got to be that way but it has been working ok so I will leave it as it is. Anyway as soon as I used Me.Combo7.enabled=true etc everything works great. Once again thank you.
 

Users who are viewing this thread

Back
Top Bottom