Repair code for acNext if there is no next record

S

Signman David

I have an event procedure that, amoung other things, selects the next record
in the form. The procedure errors out if it just processed the last record
in the form. How can I address this problem?

Here is the line item: DoCmd.GoToRecord acDataForm,
"frmPurchaseOrdersToSend", acNext
 
M

Marshall Barton

Signman said:
I have an event procedure that, amoung other things, selects the next record
in the form. The procedure errors out if it just processed the last record
in the form. How can I address this problem?

Here is the line item: DoCmd.GoToRecord acDataForm,
"frmPurchaseOrdersToSend", acNext


If Me.CurrentRecord < Me.Recordset.RecordCount Then
DoCmd.GoToRecord acDataForm, _
"frmPurchaseOrdersToSend", acNext
End If
 
S

Signman David

Thanks, Marshall; that's perfect!

Marshall Barton said:
If Me.CurrentRecord < Me.Recordset.RecordCount Then
DoCmd.GoToRecord acDataForm, _
"frmPurchaseOrdersToSend", acNext
End If
 
E

efandango

Marshall,

Do you know how I could make this work for a subform that errors stating
that the object (form) isn't open.

If Me.CurrentRecord < Me.Recordset.RecordCount Then
DoCmd.GoToRecord acDataForm, "frm_Run_Test", acNext
MsgBox "All fields are filled"

End If
 
G

George Nicholson

Subforms aren't considered to be open Forms, so you can't use GoToRecord,
which needs the name of an open form.

From the subform:
Me.Recordset.MoveNext

From the parent form (replacing NameOfSubFormControl with the name of the
Control, not the Form):
Me.NameOfSubformControl.Form.Recordset.MoveNext

HTH,
 
G

George Nicholson

You asked for a substitute for DoCmd.GoToRecord, which can't be used with a
subform. I gave you 2, depending upon where you are calling it from (Parent
or subform). Not sure what print form has to do with it or what a print form
even is.

HTH,

efandango said:
George,

Thanks for replying, though I'm not sure how your solution would fit my
particular problem, as it's not rlated to a prent form. Rather than paste
in
a great deal of code here, can I refer you to this link of my post about
the
problem:

http://www.microsoft.com/office/com...8ada&catlist=&dglist=&ptlist=&exp=&sloc=en-us
 

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