Test if any current record is available

B

Boris

One of my forms uses an unbound subform. I use the Form_Current event of the
form to set the RecordSource of the subform (thus binding the subform to a
query). The subform itself uses Form_Current, too, to access the current
record (in the subform).

The problem is that Form_Current of the subform fires first when the form is
opened. As the subform is not bound at that time it tries to access the
current record which is not yet available. What do I have to check to test
if there is any current record available? I tried Me.Count and
Me.CurrentRecord but the first one gives me strange results and the last one
runtime error 2455?

Boris
 
S

Sandra Daigle

You can determine whether the form is unbound by checking to see whether the
recordset object exists:

If Me.Recordset Is Nothing Then
MsgBox "Unbound"
End If

Also, to determine whether records exist:

If Me.Recordset Is Nothing Then
MsgBox "Unbound"
Else
If Not (Me.Recordset.EOF And Me.Recordset.BOF) Then
MsgBox "We have records"
End If
End If

Since you probably only want to check for the condition when the recordset
exists, here is the code - note that you must use the "Not <obj> Is Nothing"
syntax.

If Not Me.Recordset Is Nothing Then
If Not (Me.Recordset.EOF And Me.Recordset.BOF) Then
MsgBox "We have records"
End If
End If
 

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