Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query returns no results - Can I display a "search again box"?

Status
Not open for further replies.

RobertIngles

Technical User
Jan 20, 2011
113
CA
Hello all;

Once again I need your help. I have a form based on a user input search parameter. If there are no results for the query the form opens up as a blank form (this form is to view information not to add a new record so I have set the additions property to no). When there are no results, is there a way to have the query parameter box re-appear and tell the user "No records match your search, did you want to search again?" with Yes and No controls. If it cannot be done with a wizard could I ask that you be fairly specific regarding the placement of the code? I am just in the process of trying to understance SQL and VBA coding and would really appreciate a little more direction than you would give to someone with even basic knowledge. The querie name is QRYLaptopInfoByLaptopID and the user is asked to enter an ID number. The form using this query to display the information is FRMLaptopInfoByLaptopID.
Thanks for your help!!!
Rob
 
How are ya RobertIngles . . .

If my read is correct all you need to do is check record count using a recordset. Display yur message and [blue]ReQuery[/blue] the form if [blue]yes[/blue] is selected.

Try the following in the [blue]On Current[/blue] event of the form:
Code:
[blue]   Dim db As DAO.Database, rst As DAO.Recordset, DL As String
   
   DL = vbNewLine & vbNewLine
   Set db = CurrentDb
   Set rst = db.OpenRecordset(Me.RecordSource, dbOpenDynaset)
   
   If rst.BOF Then
      If MsgBox("No records match your search!" & DL & _
                "Do you want to search again?", _
                vbQuestion + vbYesNo, _
                "No Data Found! ...") = vbYes Then
         Me.Requery
      End If
   End If[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top