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

VBA Recordsets

Status
Not open for further replies.

pcdaveh

Technical User
Sep 26, 2000
213
US
What is the proper syntax to use to check if a record set has any records if the answer is no I don't want the error messages.

rst.nomatch 'didn't work for me.
rst.movefirst 'didn't work because there are no records.
 
Hi,

I would do:

if myrecordsetname.recordcount = 0 then exit sub

yourrecordset.recordcount will give you the number of records in the recordset.

Rgds,

Klasse
 
I always use teh following method:

Dim db as DAO.Database, rst as DAO.Recordset
Set db = CurrentDB
Set rst = db.OpenRecordset("Select * FROM Source")
If rst.RecordCount > 0 Then
'Add all code here
Else
MsgBox "No records found!", vbExclamation
End If

HTH James Goodman
 
Hi!

Checking EOF and BOF is probably the surest method:

If rst.EOF = True and rst.BOF = True Then No records.

hth Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top