Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    Hmmm, lots of beer and confusion (on my part). In your case, I don't think the combo can be null after the update.
    Anyway, I thought there was only one report requiring start and end dates. FWIW, here's another take on how it might go (warning: air code to follow).


    Code:
    Private Sub cboReports_AfterUpdate()
    
    If Me.cboReports = "Personnel Arrived (Date Range)" Then
      If IsNull([StartDate]) OR IsNull([EndDate)]) Then
        Msgbox  "A start and end date is required for the selected report."
        Exit Sub
      End if
      If Not IsDate(Me.txtStartDate) OR Not IsDate(Me.txtEndDate) Then
        Msgbox "Only valid dates can be entered into the Begin and Start date fields."
        Exit Sub
      End If
    End If
    
    End Sub
    What my air code would not do (assuming it's written correctly) is ensure the end date is not before the start date. You might be surprised that I would consider that, but hey, there's always someone who will surprise you. Nor will it validate that there are valid dates or no Nulls for the other reports, but I provide it as an example of how one might want to validate date parameters.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  2. #17
    BusDriver3 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    46
    This is what seems to work for me... Still not sure if it is clean enough...

    Code:
    Private Sub cboReports_AfterUpdate()
    If Me.cboReports Like "*(Date Range)*" And IsNull(StartDate) Then
           MsgBox ("Selecting both a Start Date and End Date is required to view this report."), vbCritical
         cboReports.SetFocus
     cboReports = ""
       Exit Sub
       End If
    If Not IsNull(cboReports) And cboReports <> "" Then
          DoCmd.OpenReport cboReports, acViewReport  ' use acViewPreview for print preview
     cboReports = ""
    Exit Sub
    End If
    End Sub

  3. #18
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Looks pretty clean in my view.
    Minor changes in blue....

    Just one thing that was mentioned earlier:
    Code:
    Private Sub cboReports_AfterUpdate()
        If Me.cboReports Like "*(Date Range)*" And (IsNull(StartDate) Or IsNull(EndDate)) Then  '<<- need to also check end date???
            MsgBox ("Selecting both a Start Date and End Date is required to view this report."), vbCritical
            Me.cboReports.SetFocus
            Me.cboReports = ""
            Exit Sub
        End If
        '
        ' maybe check to see if end date >= start date   
        ' (ex. start date = 12/14/2016 and end date = 11/25/2016 would be bad)
        '
        If Not IsNull(cboReports) And cboReports <> "" Then
            DoCmd.OpenReport cboReports, acViewReport  ' use acViewPreview for print preview
            Me.cboReports = ""
            Exit Sub
        End If
    End Sub

  4. #19
    BusDriver3 is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    46
    This works great! Thank You so much!!!!

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Msgbox-Combo
    By wickedjc in forum Modules
    Replies: 2
    Last Post: 02-16-2016, 12:02 PM
  2. VBA code for MsgBox
    By mladen273 in forum Programming
    Replies: 8
    Last Post: 01-17-2013, 10:05 PM
  3. Yes No msgbox
    By imintrouble in forum Access
    Replies: 3
    Last Post: 10-14-2011, 02:24 PM
  4. MsgBox
    By Mtyetti in forum Forms
    Replies: 4
    Last Post: 07-27-2011, 01:51 PM
  5. Msgbox with data in
    By AndycompanyZ in forum Programming
    Replies: 9
    Last Post: 06-27-2011, 07:52 AM

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