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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write If statement based on whether record is found

Status
Not open for further replies.

lin

IS-IT--Management
Aug 27, 2000
13
0
0
US
I'm trying to write an If-Then-Else statement using a DoCmd.Find Record statement.

If the record is found, I want to have it appear on the screen (which it does currently). If the record is not found I want to display a message box.

I can get the message box to display, but it displays all the time (whether the record is found or not).

Any help is appreciated. [sig][/sig]
 
You will get other responses, undoubtedly that will be in disagreement with this but here's a 'better' solution than using a DoCmd 'dot' Macro...

Private Sub Button10_Click()

Dim db as Databse
Dim rs as Recordset

Set db = DBEngine(0)(0)
set rs = db.Openrecordset("Select * from [YourTable] where [Field1]=""" & YourTextCriterion & """")

If not rs.EOF and not rs. BOF then
'item exists do something with it. Like display it perhaps?
Else
'item does'nt exist. Display message box
End If

End Sub

More? Let me know. B-) [sig]<p>Amiel<br><a href=mailto:amielzz@netscape.net>amielzz@netscape.net</a><br><a href= > </a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top