Consulting

Results 1 to 5 of 5

Thread: Need help with writing a if then statement

  1. #1

    Need help with writing a if then statement

    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?

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    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

  3. #3
    Quote Originally Posted by OBP View Post
    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: =

  4. #4
    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

  5. #5
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Can you explain what you are trying to achieve?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •