Opening form to new record

G

Guest

When I run the following code, I get an error message "can't find "l"
referred to in expression". Can you please help me with what I'm doing wrong.

stDocName = "MAINFRM"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCMD.Gotorecord, [mainfrm], ac.newrec, [mainfrm]

Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click

End Sub
 
J

John Vinson

When I run the following code, I get an error message "can't find "l"
referred to in expression". Can you please help me with what I'm doing wrong.

stDocName = "MAINFRM"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCMD.Gotorecord, [mainfrm], ac.newrec, [mainfrm]

Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click

End Sub

It sounds like the textbox on your form named [mainfrm] contains "1".
The first argument for GoToRecord should be the type of object (acForm
is a builtin constant for the purpose); the second argument is a text
string for the name of the form; and the third argument is the desired
record position. I'd suggest

DoCmd.GoToRecord acForm, "YourFormNameHere", [mainfrm]

assuming that mainfrm is a textbox containing the desired record
position.

John W. Vinson[MVP]
 

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

Similar Threads


Top