Combining If Statements

bxc4904

New member
Local time
Today, 14:59
Joined
May 11, 2007
Messages
6
I've written the code below to change the Tab Stop and Visible properties of some of my controls based on the value returned from a combo box. The code is on the On Update event of the combo box. As you can see there are only 2 different resulting sets of actions for 7 different values. Is it possible to combine the If/Then statements for the like actions? For example, combine If Me.cboDisp.Value = "Repair" and If Me.cboDisp.Value = "Acceptable As Is" into something like If Me.cboDisp.Value = "Repair" Or "Acceptable As Is"? I already know it won't work as written, it's just to get the general idea across. The code below works fine and does exactly what I need it to do. I am just wondering if there is an easier way to do it. If anyone knows, I would certainly appreciate the help.

If Me.cboDisp.Value = "Repair" Then
Me.Stress.Visible = True
Me.Stress.TabStop = True
Me.Stress.Value = ""
Me.StressDate.Visible = True
Me.StressDate.TabStop = True
Me.CustApp.Visible = True
Me.CustApp.TabStop = True
End If
If Me.cboDisp.Value = "Acceptable As Is" Then
Me.Stress.Visible = True
Me.Stress.TabStop = True
Me.Stress.Value = ""
Me.StressDate.Visible = True
Me.StressDate.TabStop = True
Me.CustApp.Visible = True
Me.CustApp.TabStop = True
End If
If Me.cboDisp.Value = "Rework to Blueprint" Then
Me.Stress.Visible = False
Me.Stress.TabStop = False
Me.Stress.Value = "N/A"
Me.StressDate.Visible = False
Me.StressDate.TabStop = False
Me.CustApp.Visible = False
Me.CustApp.TabStop = False
End If
If Me.cboDisp.Value = "Scrap" Then
Me.Stress.Visible = False
Me.Stress.TabStop = False
Me.Stress.Value = "N/A"
Me.StressDate.Visible = False
Me.StressDate.TabStop = False
Me.CustApp.Visible = False
Me.CustApp.TabStop = False
End If
If Me.cboDisp.Value = "Regrade" Then
Me.Stress.Visible = False
Me.Stress.TabStop = False
Me.Stress.Value = "N/A"
Me.StressDate.Visible = False
Me.StressDate.TabStop = False
Me.CustApp.Visible = False
Me.CustApp.TabStop = False
End If
If Me.cboDisp.Value = "Return to Vendor" Then
Me.Stress.Visible = False
Me.Stress.TabStop = False
Me.Stress.Value = "N/A"
Me.StressDate.Visible = False
Me.StressDate.TabStop = False
Me.CustApp.Visible = False
Me.CustApp.TabStop = False
End If
If Me.cboDisp.Value = "Recertify" Then
Me.Stress.Visible = False
Me.Stress.TabStop = False
Me.Stress.Value = "N/A"
Me.StressDate.Visible = False
Me.StressDate.TabStop = False
Me.CustApp.Visible = False
Me.CustApp.TabStop = False
End If
 
It is very simple infact you are pretty well there. Just use an if statement like this

Code:
If Me.cboDisp.Value = "Repair" or Me.cboDisp.Value = "Acceptable As Is" then
You can have several more values if you need them
 
Hi

what you can do is set all the controls tag property to something like "CtrlSet" and then using the following code:

Code:
Dim ctrl As Control

For Each ctrl In Me.Controls
        
       If ctrl.Tag = "CtrlSet" Then
         ctrl.Visible = True
         ctrl.TabStop = True
       End If
    
 Next ctrl
 
bxc,

Code:
Select Case Me.cboDisp
   Case "Repair" 
      Me.Stress.Visible = True
      Me.Stress.TabStop = True
      Me.Stress.Value = ""
      Me.StressDate.Visible = True
      Me.StressDate.TabStop = True
      Me.CustApp.Visible = True
      Me.CustApp.TabStop = True
   Case "Acceptable As Is", "Rework to Blueprint", "Scrap", "Regrade", "Return to Vendor", "Recertify"
      Me.Stress.Visible = False
      Me.Stress.TabStop = False
      Me.Stress.Value = "N/A"
      Me.StressDate.Visible = False
      Me.StressDate.TabStop = False
      Me.CustApp.Visible = False
      Me.CustApp.TabStop = False
   End Select

Wayne
 
Thanks to both of you. For now I think I'll try the Or route since it's not much different from what I'm familiar with. I'm going to have to go to my experimental db and practice with the CtrlSet, though. That looks interesting.
Either way this will save me a lot of time and space in the future.
 
Wayne,

The reason I hadn't tried select case is that I thought it would only do true/false on one condition. That sounds even easier. Thanks.

Bruce
 
Bruce,

Thanks, kinda cool that you got three responses so quickly. Rabbie's and Max's
solutions are viable too.

See ya,
Wayne
 

Users who are viewing this thread

Back
Top Bottom