[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Message Box, No Records Found

Posted on 2011-09-04
2
Medium Priority
?
446 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 - Microsoft MVP, Access and Data Platform) earned 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Suggested Courses
Course of the Month20 days, 13 hours left to enroll

864 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