Log in

View Full Version : Need help with writing a if then statement



mustang88
10-30-2019, 11:26 PM
I have a combo box with several different plans to choose from in cboOption. Example1 and Example2 are text boxes that check to see if Example1 is greater than Example2. Two of the plans has to be Nz(Me.Example1, 0) < Nz(Me.Example2, 0).

I currently get Compile Error Expected: =

If Me.cboOption = "Plan 1" Or Me.cboOption "Plan 2" Then
Nz(Me.Example1, 0) < Nz(Me.Example2, 0)
Else
Nz(Me.Example1, 0) > Nz(Me.Example2, 0)
End If

I.am guessing, I wrote it wrong. How would you write what I am looking for?

OBP
10-31-2019, 02:11 AM
This If Me.cboOption = "Plan 1" Or Me.cboOption "Plan 2" Then
Should be
If Me.cboOption = "Plan 1" Or Me.cboOption = "Plan 2" Then

mustang88
10-31-2019, 05:55 AM
This If Me.cboOption = "Plan 1" Or Me.cboOption "Plan 2" Then
Should be
If Me.cboOption = "Plan 1" Or Me.cboOption = "Plan 2" Then

That's what I had as well, and I still get Compile Error Expected: =

mustang88
10-31-2019, 07:06 AM
I kind of got it working, except the code is stuck on "MsgBox "You number must be greater than Example2.", vbInformation, "Invalid Entry:" it will not move on to the else statement.

Dim msg1 As String
Dim msg2 As String

If Me.cboOption.Column(0) & "1" Or Me.cboOption.Column(0) & "2" Then
msg1 = Nz(Me.Example1, 0) < Nz(Me.Example2, 0)
Cancel = True
MsgBox "You number must be greater than Example2.", vbInformation, "Invalid Entry:"
Else
If Me.cboOption.Column(0) & "" <> Me.cboOption.Column(0) & "1" And Me.cboOption.Column(0) & "2" Then
msg2 = Nz(Me.Example1, 0) > Nz(Me.Example2, 0)
Cancel = True
MsgBox "You number must be less than Example2.", vbInformation, "Invalid Entry:"
End If
End If

OBP
10-31-2019, 09:25 AM
Can you explain what you are trying to achieve?