UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Runtime error 2046 on doCmd.gotoRecord after doCmd.openReport, Office 2007    
 
   
Alexie
post Jun 1 2010, 04:33 PM
Post#1



Posts: 2
Joined: 1-June 10



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?
How could I solve the problem as I really want to run the two DoCmd in one button?
Please Help, Thanks!
Go to the top of the page
 
vtd
post Jun 1 2010, 06:03 PM
Post#2


Retired Moderator
Posts: 19,667
Joined: 14-July 05



Try the GoToRecord statement before the OpenReport statement.
Go to the top of the page
 
Alexie
post Jun 1 2010, 10:52 PM
Post#3



Posts: 2
Joined: 1-June 10



Thanks Van for reply. That works I know. what I really want is to print out current record and then goto new entry.
Go to the top of the page
 
vtd
post Jun 3 2010, 12:06 AM
Post#4


Retired Moderator
Posts: 19,667
Joined: 14-July 05



Many possible ways:
. Open the Report in Dialog mode to suspend the execution of the code in the Form. With the OpenReport statement before the GoToRecord, Access will open the Report and suspend the GoToRecord statement until the Report is close. When the Report is closed, the Form becomes the active Data Object and the GoToRecord should be fine.
2. Use the Report_Close Event to run the GoToRecord statement applicable to the Form.
3. Temporarily store some value, e.g. PK that uniquely identify the CurrentRecord on the Form, in a VBA variable execute GoToRecord and the OpenReport using the VBA variable in the WhereCondition argument of the OpenReport statement to filter the Report to the CurrentRecord on the Form.
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    21st October 2018 - 10:29 PM