Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2005

    Unanswered: MsgBox if query returns null set

    So I've got a search form that populates the expressions in a search query and then opens a form which displays the results of the search query. If the search criteria returns a null set in the query, I would like to display a dialog box that says "Your search returned no results." So i added the following code in the OnLoad event in the form which displays the query results:

    If Form!ClaimID = "" Then MsgBox "Your search returned no results"

    I get the following error message:
    Runtime Error 2427
    You entered an expression that has no value.

    Yes, I know it has no value, that's why I want a dialog box to tell the user that in a nice way... Any clues?


  2. #2
    Join Date
    Mar 2003
    The Bottom of The Barrel
    Provided Answers: 1
    A zero length string is not null, it's a zero length string.


    If IsNull(Form!ClaimID) Then MsgBox "Your search returned no results"
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Dec 2005
    no error message with that code, but no messagebox either...

    this worked:
    If Me.Recordset.RecordCount = 0 Then
    MsgBox "Your search returned no results"
    DoCmd.Close acForm,
    End If
    Last edited by andyg75; 01-04-06 at 16:01.

  4. #4
    Join Date
    Jun 2003
    And for a similar idea here is something I sometimes put in code behind the form of a form's FormLoad property:

    ' Check for no recs (i.e. if cur rec is new rec) and if so then msg.
    If Me.NewRecord Then
    MsgBox "No records matched the criteria." & Chr(13) & Chr(10) & Chr(10) & "You may continue with the new record or else close the form.", vbExclamation
    End If
    J. Paul Schmidt, Freelance Web and Database Developer
    Access Database Sample, Web Database Sample, ASP Design Tips

Posting Permissions

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