Results 1 to 6 of 6
  1. #1
    octsim is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    15

    Catch empty search result

    Hey there,

    I created a search form which can search in 3 different fields of a table.
    I'm trying to get a Messagebox to pop up if the table does not contain anything with those search strings.
    Is that possible and if yes, how?

    Thanks in advance



    octsim

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Post the code to show us how you are searching the tables.

  3. #3
    octsim is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    15
    The SQL Code is this:

    Code:
    SELECT Tablename.Serial, Tablename.Keyword.... loads of more fields that need to be displayed
    FROM Tablename
    WHERE (((Tablename.Serial) Like "*" & [Forms]![SearchForm]![Serial] & "*") AND ((Tablename.Keyword) Like "*" & [Forms]![SearchForm]![Keyword] & "*") AND ((Tablename.Comment) Like "*" & [Forms]![SearchForm]![Comment] & "*"));

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    You can place some code in the form's load event.

    Dim rcd As Recordset
    Set rcd = Me.RecordsetClone
    If rcd.RecordCount <= 0 Then
    msgBox "Your query returned zero records"
    docmd.close

    Exit Sub
    End If

  5. #5
    octsim is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Posts
    15
    That doesn't work.
    I get an error in the "Set rcd = ... " line saying runtime error 7951
    I guess that's because I have an unbound form.
    My form has those 3 textboxes and calls a query (SQL code I have posted) when the "Search" button is pressed.
    Do I have to restructure the whole search form?

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by octsim View Post
    Do I have to restructure the whole search form?
    I don't think so.

    You could include your SQL within DAO and open a recordset to get a recordcount.

    Try the following. Pass your SQL to a string and then open a recordset

    Dim strSQL as string
    strSQL = "My SELECT Query inserted HERE"

    Dim rcd As DAO.Recordset
    Set rcd = CurrentDB.OPenRecordset (strSQL, dbOPenDynaset)
    rcd.movelast
    If rcd.RecordCount <= 0 Then
    msgBox "Your query returned zero records"

    End If

    Set rcd = Nothing

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

Similar Threads

  1. Return the result of a search
    By Loc in forum Programming
    Replies: 11
    Last Post: 06-12-2013, 06:23 PM
  2. How to catch oracle exception error
    By nvrwrkn in forum Programming
    Replies: 2
    Last Post: 10-09-2012, 06:06 AM
  3. Highlight key search result
    By uronmapu in forum Access
    Replies: 28
    Last Post: 06-17-2012, 09:32 AM
  4. When a query result is empty.....
    By khanson in forum Queries
    Replies: 3
    Last Post: 08-01-2011, 09:12 PM
  5. Controls go blank on empty query result
    By kevdfisch in forum Programming
    Replies: 4
    Last Post: 08-25-2009, 08:07 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