Code doesn't work with blanked table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Yes. Before using MoveFirst or MoveLast on a new Recordset, you should
always check RecordCount > 0 or .EOF = False.
 
Back
Top