Recordset Object

  • Thread starter Thread starter Wes Peters
  • Start date Start date
W

Wes Peters

I'm trying to programatically determine if a form's underlying recordset is
empty or not. I've tried checking Me.Recordset.RecordCount and
Me.Recordset.EOF with no success. What would be the best approach? I'm
using Access 2000 / SQL2000

Thanks,
Wes
 
Try CurrentRecord

You could use two ways. The one I always use is to first check the recordcount of the recordsource before opening the form.
- I have a global variable in a module
Public srcFrmPersons as String
- When clicking on the "Open Form" button, is write in code something like:
Code:
blnOpenForm=True
srcFrmPersons = "SELECT * FROM Persons;"
rs.Open srcFrmPersons, CurrentProject.Connection
if rs.EOF then
   blnOpenForm = False
   MsgBox "The form contains no data"
end if
rs.Close
if blnOpenForm then Docmd.OpenForm "Persons"

Secondly I add to the OnOpen event of the Form Persons:
Code:
if srcFrmPersons = "" then srcFrmPersons = "SELECT * FROM Persons"
Me.RecordSource = srcFrmPersons

A second way to do this, is to check on the CurrentRecord property of the form (then you have opened the form already)

Code:
If Me.CurrentRecord = 0 Then
 DoCmd.Close acForm, Me.Name
End if
 
Wes Peters said:
I'm trying to programatically determine if a form's underlying recordset is
empty or not. I've tried checking Me.Recordset.RecordCount and
Me.Recordset.EOF with no success. What would be the best approach? I'm
using Access 2000 / SQL2000

Thanks,
Wes

I wonder what you mean by "no success"?

Anyway, it's far better to use the form's recordsetclone e.g. test for:

Me.RecordsetClone.Recordcount = 0

There seems to be something terminally buggy about the form Recordset
property. As soon as you start referring to it, Access gets very uppity and
a crash is inevitable.
 
I've experienced those terminally buggy crashes and will stay away from the
Recordset property. The RecordsetClone seems to do the trick.

Thanks.
 
Back
Top