First let me premise with I am very new to access vba.
My question is I have several if then else statements in a row for example
If Me.txtRevenuePerHour.Value < 90 Then
Me.chkRPH.Value = -1
Me.chkRPH.Enabled = "False"
End If
If Me.txtLoadTime.Value < 0.25 Then
Me.chkLT15.Value = -1
Me.chkLT15.Enabled = "False"
End If
I was wondering if there is another way besides rewriting the if statements over and over again. If not then I will accept that but just curious if there is another way.
The if statements check a checkbox control if certain conditions are met. Most are different conditions but some are the same
Thank you ahead of 开发者_开发问答time
The code for each if uses completely different objects and conditions in the If
clause and inside the If
blocks different objects are used as well.
There is no way to generalize the If
itself, thought the body of the If
may be:
Untested code:
Sub DisableAndSetToMinusOne(ctrl As Control)
ctrl.Value = -1
ctrl.Enabled = "False"
End Sub
If Me.txtRevenuePerHour.Value < 90 Then
DisableAndSetToMinusOne(Me.chkRPH)
End If
If Me.txtLoadTime.Value < 0.25 Then
DisableAndSetToMinusOne(Me.chkLT15)
End If
精彩评论