Code doesn't work with blanked table

D

Daniel

Good morning,

I have the following code

**************
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Drawing History Tbl")
Dim a As Integer
a = 0

With rst
.MoveLast
Do Until .BOF
If rst("Drawing Number") = Forms![Drawing Management
Frm]![Drawing Number].Value And rst("Drawing Issue") = Me.Combo2.Value Then
a = 1
End If
.MovePrevious
Loop
End With

***********

My problem is that it only work if I already have at least one record in the
table in question. Recently, I had to blank the database for a new project
and obviously this code generated an error. I would like to know how I can
detect the number of records in a table. I would like to create an if
statement that will do one thing if the table is currently empty and another
if there are already entries.

Thanks for the help!

Daniel
 
D

Daniel

Problem solved,

I used a .recordcount to verify if the table was blanked or not.

Daniel
 
V

Van T. Dinh

Yes. Before using MoveFirst or MoveLast on a new Recordset, you should
always check RecordCount > 0 or .EOF = False.
 

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