EOF in Subform

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

Guest

I'm using the following code:

Private Sub Paid_Date_KeyDown(Shift As Integer)
On Error GoTo Err_Paid_Date_KeyDown
If Shift = acCtrlMask Then
Me.paid_date = Me.inv_date

Set rst = Me.Recordset.Clone
If rst.EOF = True Then 'Here's the problem
Me![OrderReview].[Final].Set Focus
Else
DoCmd.GoToRecord
End If
End If
Exit_Paid_Date_KeyDown:

The EOF test does not work. Even though there is only one record in the
subform, EOF is always false. What am I doing wrong?
 
David said:
I'm using the following code:

Private Sub Paid_Date_KeyDown(Shift As Integer)
On Error GoTo Err_Paid_Date_KeyDown
If Shift = acCtrlMask Then
Me.paid_date = Me.inv_date

Set rst = Me.Recordset.Clone
If rst.EOF = True Then 'Here's the problem
Me![OrderReview].[Final].Set Focus
Else
DoCmd.GoToRecord
End If
End If
Exit_Paid_Date_KeyDown:

The EOF test does not work. Even though there is only one record in
the subform, EOF is always false. What am I doing wrong?

What is it you're trying to detect? The clone recordset will be
positioned at its first record, if there is one, in which case rst.EOF
will be False. At the point where you're testing it, rst.EOF would only
be true if the recordset contained no records.

If you just want to know whether the subform (where I gather this code
is running) is at a new record, you don't need to clone the recordset at
all. Just say

If Me.NewRecord Then

But since I'm not sure what you're trying to do, I can't really say if
that's what you need.

And your declaration of the KeyDown event procedure is incorrect. It
should be

Private Sub Paid_Date_KeyDown(KeyCode As Integer, Shift As Integer)

(though that may have been wrapped to two lines by the newsreader
although it belongs on one line).
 
OK...
What I am trying to do is exit the subform using setfocus when there are no
additional records to edit. Addition of new records is not permitted in the
form so I don't believe your suggested line would work since the form will
not permit moving to a new record.

And thanks for the correction on the KeyDown event. I had accidentally
deleted the missing line.
 
Itried your suggested line...

If Me.NewRecord Then

I keep getting the error... "Can't move to specified record."

Any other ideas?
 
David said:
OK...
What I am trying to do is exit the subform using setfocus when there
are no additional records to edit. Addition of new records is not
permitted in the form so I don't believe your suggested line would
work since the form will not permit moving to a new record.

I see. What you really want to know is whether the current record is
the last one on the subform. Try code like this:

With Me.RecordsetClone
.MoveLast
If .AbsolutePosition = (Me.CurrentRecord - 1) Then
' you're on the last record
Else
' you're not
End If
End With

I'm not sure that the rest of the code you posted is correct. Is this
KeyDown event procedure taking place on the subform? Is this line ...
Me![OrderReview].[Final].Set Focus

.... supposed to set the focus back to the main form ("OrderReview" being
that form)? It won't.
 
Back
Top