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
6
  • 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? Commented Oct 8, 2019 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. Commented Oct 8, 2019 at 14:05
  • 1
    Thank you!! when I changed to to <1 it work. Commented Oct 8, 2019 at 14:06
  • Yay we did it! :D Commented Oct 8, 2019 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? Commented Oct 8, 2019 at 14:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.