Solved

Message Box, No Records Found

Posted on 2011-09-04
2
430 Views
Last Modified: 2012-08-13
I have the following coding in a Access 2007 form with Sub Forms.  I have a find button that on click the
coding finds the record in the database.  However, I need a messag box to appear when find is selected and no records are found.  Where do I put this and what coding do I use?  

Private Sub Command9_Click()

Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[PK_DriverLicenseID] = '" & Me.Text10 & "'"
If Not rs.EOF Then
Me.Bookmark = rs.Bookmark


End If
End Sub
0
Comment
Question by:jjc9809
  • 2
2 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 36481559

Private Sub Command9_Click()

Dim rs As DAO.Recordset

Set rs = Me.Recordset.Clone
rs.FindFirst "[PK_DriverLicenseID] = '" & Me.Text10 & "'"
If rs.NoMatch = True Then
    ' Not Found
    ExitSub
Else
    Me.Bookmark = rs.Bookmark
End If
End Sub

mx
0
 
LVL 75
ID: 36481681
And we can simplify this also (and there was a typo above ... ExitSub - no space)

    With Me.Recordset.Clone
        .FindFirst "[PK_DriverLicenseID] = '" & Me.Text10 & "'"
        If .NoMatch = True Then
            ' Not Found - Do whatever
            Exit Sub
        Else
            Me.Bookmark = .Bookmark
        End If
    End With

mx
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now