Solved

Message Box, No Records Found

Posted on 2011-09-04
2
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

695 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