Results 1 to 5 of 5
  1. #1
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    If Statement Criteria Needed for form

    Don't know why this is not working; What am I getting wrong?
    It stops at OrderEntrymsgbox

    If IsNull([BeginningOrderDate]) Or IsNull([EndingOrderDate]) Then
    MsgBox "You must enter both beginning and ending dates."
    DoCmd.GoToControl "BeginningOrderDate"
    Else
    If [BeginningOrderDate] > [EndingOrderDate] Then
    MsgBox "Ending date must be greater than Beginning date."
    DoCmd.GoToControl "BeginningOrderDate"
    Else
    Me.Visible = False
    End If

    If IsNull([BeginningOrderDate]) Or IsNull([EndingOrderDate]) Then
    OrderEntrymsgbox = MsgBox("Preview Report Witn NO Date(s)?", vbInformation + vbYesNo, "ReportList")

    If (OrderEntrymsgbox = vbYes) Then
    DoCmd.SetWarnings False
    DoCmd.OpenReport Me.List2, acViewPreview


    DoCmd.Close acForm, Me.Name
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I am surprised it runs at all. Missing End If lines and the first Else needs to be ElseIf.
    Code:
    If IsNull([BeginningOrderDate]) Or IsNull([EndingOrderDate]) Then
       MsgBox "You must enter both beginning and ending dates."
       DoCmd.GoToControl "BeginningOrderDate"
    ElseIf [BeginningOrderDate] > [EndingOrderDate] Then
       MsgBox "Ending date must be greater than Beginning date."
       DoCmd.GoToControl "BeginningOrderDate"
    Else
       Me.Visible = False
       If IsNull([BeginningOrderDate]) Or IsNull([EndingOrderDate]) Then
          OrderEntrymsgbox = MsgBox("Preview Report Witn NO Date(s)?", vbInformation + vbYesNo, "ReportList")
      End If
       If (OrderEntrymsgbox = vbYes) Then
          DoCmd.SetWarnings False
          DoCmd.OpenReport Me.List2, acViewPreview
          DoCmd.Close acForm, Me.Name
      End If
    End If
    End Sub
    I have never used GoToControl. If it doesn't work try SetFocus:
    Me.BeginningOrderDate.SetFocus
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383

    still not working

    It says variable not defined ?
    Attached Thumbnails Attached Thumbnails ErrorOnIfStatement.jpg  

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    You have Option Explicit in the module header?

    If so, must declare all variables with a DIM statement.

    Alternative code that doesn't require that variable:
    Code:
    Else
       Me.Visible = False
       If IsNull([BeginningOrderDate]) Or IsNull([EndingOrderDate]) Then
          If MsgBox("Preview Report Witn NO Date(s)?", vbInformation + vbYesNo, "ReportList") = vbYes Then
             DoCmd.SetWarnings False
             DoCmd.OpenReport Me.List2, acViewPreview
             DoCmd.Close acForm, Me.Name
          End If
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Thanks, that worked.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 11-19-2012, 01:59 PM
  2. If Statement Criteria Needed for form
    By burrina in forum Forms
    Replies: 6
    Last Post: 11-16-2012, 11:00 PM
  3. Replies: 11
    Last Post: 03-21-2012, 12:51 PM
  4. Query Criteria help needed
    By iuianj07 in forum Queries
    Replies: 1
    Last Post: 01-21-2011, 02:57 PM
  5. Passing Criteria to IN statement from Form
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-09-2009, 04:02 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums