Hi Everyone,
I have written code to look up a value in a table that then enables or disables a subform in my main form. The code works, but I know it is now as efficient as it can be. The main problem is that I have multiple values that determine if the subform should be enabled or disabled. I would like to use an IN statement but I'm pretty sure this doesn't work for Dlookup. Below is an example of the code I currently have:
Like I said, this works fine, but I am concerned if I need to add more items to look up and the stability of the code in general.
Please let me know if there is a way to condense the code and make it more efficient, or if you have any questions. I appreciate any help you can give!
Thanks!
I have written code to look up a value in a table that then enables or disables a subform in my main form. The code works, but I know it is now as efficient as it can be. The main problem is that I have multiple values that determine if the subform should be enabled or disabled. I would like to use an IN statement but I'm pretty sure this doesn't work for Dlookup. Below is an example of the code I currently have:
Code:
Sub enablecontrols(setting As Boolean)
Inv_subform.Enabled = setting
End Sub
Private Sub Form_Current()
If DLookup("Description", "Line Items", "ID=" & Me.ID) = "Test1" Then
enablecontrols (True)
Else: enablecontrols (False)
End If
End Sub
Private Sub Form_Current1()
If DLookup("Description", "Line Items", "ID=" & Me.ID) = "Test2" Then
enablecontrols (True)
Else: enablecontrols (False)
End If
End Sub
Private Sub Form_Current2()
If DLookup("Description", "Line Items", "ID=" & Me.ID) = "Test3" Then
enablecontrols (True)
Else: enablecontrols (False)
End If
End Sub
Private Sub Form_Current3()
If DLookup("Description", "Line Items", "ID=" & Me.ID) = "Test4" Then
enablecontrols (True)
Else: enablecontrols (False)
End If
End Sub
Like I said, this works fine, but I am concerned if I need to add more items to look up and the stability of the code in general.
Please let me know if there is a way to condense the code and make it more efficient, or if you have any questions. I appreciate any help you can give!
Thanks!