开发者

Several If Statements in an access 2007 vba subroutine. Curious if there is another way?

开发者 https://www.devze.com 2023-03-20 09:26 出处:网络
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

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
0

精彩评论

暂无评论...
验证码 换一张
取 消