Runtime error 2046 on doCmd.gotoRecord after doCmd.openReport (1 Viewer)

Alexie

New member
Local time
Today, 03:35
Joined
Jun 1, 2010
Messages
2
In a form, I have a button with the following sub onClick:
Private Sub btn_both_Click()
DoCmd.OpenReport "R_products", acViewPreview
DoCmd.GoToRecord acDataForm, "F_products", acNewRec
End Sub

But when I click on the button, that 2046 error occurs, "The command or action 'GotoRecord" isn't available now"

Interestingly, if I run that two DoCmd in 2 buttons separately in the form with the following code, they all works fine.
Private Sub btn_New_Click()
DoCmd.GoToRecord acDataForm, "F_products", acNewRec
End Sub

Private Sub btnRpt_Click()
DoCmd.OpenReport "R_products", acViewPreview
End Sub
it seems that that two DoCmd can't be running in a same precedure or I missed something?

Please help! Thanks a lot!
 
Last edited:

KenHigg

Registered User
Local time
Today, 06:35
Joined
Jun 9, 2004
Messages
13,327
Seems you should close the report before opening the form?
 

Alexie

New member
Local time
Today, 03:35
Joined
Jun 1, 2010
Messages
2
Ken, The form (where the "do both" button is ) is opened. You meant close the report before gotoRecord?

What I really want to do is, by clicking one button, to print a report and then go to NewRec for new entry.

I tried to use Macro, but same error.

Such error is very easy to reproduce. Wonder if any one had the same problem on their system?
 

KenHigg

Registered User
Local time
Today, 06:35
Joined
Jun 9, 2004
Messages
13,327
Hum... Since you have the report in preview the maybe do the goto new record in a report event like when it closes or prints?
 

Users who are viewing this thread

Top Bottom