Hi!
I want to create a dynamic IF statement linked to a table. The end purpose is to determine a customer's eligibility for a certain promotion. Since our programs and the qualifications for them are ever-changing, I want to be able to set up a table that the end-user could edit without getting scared off by VBA.
So, the users will bring up a customer's information on a form, and the eligibility will depend on a few different factors (i.e. state they live in, term of subscription, relationship name, etc.). I can work out all the complicated stuff later...All I need to have is a way to take a condition ex. (STATE = "NJ"), which would be written in a cell in my CONDITIONS table, and have it actually evaluate that in the code on my form.
So far I have the following:
The Conditions Table has such things as:
ID | Criteria1 | Eligible
1 | State="NJ" | No
2 | State="VT" | Yes
And it should theoretically cycle through each ID until, using the data inputted on the form, both the Criteria1 = True and Eligible <> "No".
If I just do
it returns the correct True or False value based on how State is filled out on the form vs. the criteria in the Conditions table, but if I try to use it in an IF statement, it throws
"Run-time error '2431': The expression you entered contains invalid syntax"
Can anyone help me fix this or suggest a better way to do this?
Thanks!!
I want to create a dynamic IF statement linked to a table. The end purpose is to determine a customer's eligibility for a certain promotion. Since our programs and the qualifications for them are ever-changing, I want to be able to set up a table that the end-user could edit without getting scared off by VBA.
So, the users will bring up a customer's information on a form, and the eligibility will depend on a few different factors (i.e. state they live in, term of subscription, relationship name, etc.). I can work out all the complicated stuff later...All I need to have is a way to take a condition ex. (STATE = "NJ"), which would be written in a cell in my CONDITIONS table, and have it actually evaluate that in the code on my form.
So far I have the following:
Code:
Private Sub EvaluateEligibility_Click()
CurrentRow = 1
Makeitstop = False
Do While Makeitstop = False
If Eval("Forms.CustomersForm." & DLookup("[Criteria1]", "Conditions", "[ID] = " & CurrentRow)) = True Then
If DLookup("[Eligible]", "Conditions", "[ID] = " & CurrentRow) <> "No" Then
MsgBox DLookup("[Eligible]", "Conditions", "[ID] = " & CurrentRow)
Makeitstop = True
End If
End If
CurrentRow = CurrentRow + 1
Loop
End Sub
ID | Criteria1 | Eligible
1 | State="NJ" | No
2 | State="VT" | Yes
And it should theoretically cycle through each ID until, using the data inputted on the form, both the Criteria1 = True and Eligible <> "No".
If I just do
Code:
MsgBox Eval("Forms.CustomersForm." & DLookup("[Criteria1]", "Conditions", "[ID] = " & CurrentRow)) = True
"Run-time error '2431': The expression you entered contains invalid syntax"
Can anyone help me fix this or suggest a better way to do this?
Thanks!!
Comment