Results 1 to 3 of 3
  1. #1
    Paok is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    4

    How to create a “no results” message box in a search form?

    Hey all
    I have an access DB, where I have a "Quick search" form that is a simple text box that opens my "Customer Viewer" form on the record that is searched. Now what I want to add is some sort of an error-handler that prompts a "No result" message box in a case where there is no match to the search(instead of the current situation where it just opens my "Customer Viewer" form with no data.
    This is my current code for clicking the search button:


    Code:
     Private Sub btnSearch_Click()
    DoCmd.OpenForm "frmCustomerViewer", acNormal, , "[FirstName]='" & Me.txtSearchBox & "' OR [LastName]='" & Me.txtSearchBox & "'"
    End Sub
    Thanks in advance

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    Maybe:

    If DCount("*", "tablename", "[FirstName]='" & Me.txtSearchBox & "' OR [LastName='" & Me.txtSearchBox & "'") > 0 Then
    MsgBox ...
    Else
    DoCmd. ...
    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.

  3. #3
    Paok is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    4
    Thanks June7 it works great
    anyway I don't want to open that specific form if there are no results, but I might just use your solution to open another form instead..
    cheers

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

Similar Threads

  1. Replies: 3
    Last Post: 09-02-2013, 04:33 PM
  2. Create Message Box based on query results
    By stanley721 in forum Queries
    Replies: 7
    Last Post: 02-14-2013, 10:04 AM
  3. Replies: 7
    Last Post: 09-21-2012, 03:30 PM
  4. Replies: 5
    Last Post: 07-13-2012, 01:15 AM
  5. Replies: 1
    Last Post: 10-24-2010, 04:01 PM

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