Find record on a form

E

Emmy

Hello,
I have a button on a form that runs the following to find
a record. When I enter the account # and it finds the
record, I don't want to manually have to close the find
box every time. Is there a way to make it close the box
after it finds the record?

Private Sub FindAccount_Click()
On Error GoTo Err_Find_Record_Click

Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, ,
acMenuVer70

Exit_Find_Record_Click:
Exit Sub

Err_Find_Record_Click:
MsgBox Err.Description
Resume Exit_Find_Record_Click

End Sub


Thanks!
Emmy
 
G

Graham R Seach

Emmy,

Replace the following two lines:
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

....with this...
Dim rs As DAO.Recordset

Set rs=Me.RecordsetClone
'******
'In the rs.FindFirst line (below) change 'AccountNo' to the name of the
'AccountNo field in the table/query, then change Me!txtAccountNo to
'the name of the textbox/control containing the Account No you've
'entered on the form
'******
rs.FindFirst "AccountNo = """ & Me!txtAccountNo & """"
If Not rs.NoMatch Then
Me.Bookmark = rs.Bookmark
End If

rs.Close
Set rs = Nothing

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top