0

I've seen a number of post about not opening a query if the query is blank but not sure where to have the code to check the output of the query. Before the query is run i have a number of conditions, if they are met then the query is opened. When i run the code below, the query opens and I do not get the message box.

Private Sub BetweenDates_Click()
    If IsNull(Me.DateMin) Then
        MsgBox "Enter starting date"
        EXIT SUB
    End If

    If IsNull(Me.DateMax) Then
        MsgBox "Enter ending date"
        EXIT SUB
    End If

    If (Forms![2ndfrm_AddEditView]![CbCATracker1] = True) Then
        DoCmd.OpenQuery "SearchCaTrackerCLUpdatedOn_Bt_qry"
    end if 

    If DCount("*", "SearchCaTrackerCLUpdatedOn_Bt_qry") > 0 Then
       MsgBox ("No records for that date range")
       EXIT SUB
    End If
braX
  • 11,506
  • 5
  • 20
  • 33
hIlary
  • 85
  • 1
  • 9
  • 1
    IDK maybe its because I havent had enough caffiene yet but it looks like your check for 0 records looks for greater than 0 - should it be less than one? At least thats what I am to conclude based on the error message for it? – Doug Coats Oct 08 '19 at 14:00
  • I also added Exit Subs to your validations. Most of the time you might want to stop executing unnecessary code if validations fail. But feel free to let me know fi this was intentional. – Doug Coats Oct 08 '19 at 14:05
  • 1
    Thank you!! when I changed to to <1 it work. – hIlary Oct 08 '19 at 14:06
  • Yay we did it! :D – Doug Coats Oct 08 '19 at 14:08
  • I have other check boxes and if statements. How do I keep it from showing a message for each query that is blank? – hIlary Oct 08 '19 at 14:56
  • @hllary Just remove the message box part – Doug Coats Oct 08 '19 at 15:05

0 Answers0