Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DoCmd.GoToRecord - help with correct syntax

Status
Not open for further replies.

kgreen

Technical User
Sep 11, 2000
32
GB
I am having problems refering to a field or control on a subform.

What I am trying to do is this:
I have a main form called [FrmItems] and 2 subforms [SubFrm1] & [SubFrm2]. Both sub forms are displayed as datasheets and on [SubFrm1] is a field or control called [ItemID]. I also have a button on the *MAIN* form that the user, (after first selecting a record in [Subfrm1]), clicks and this then runs a query.

I then want access to move to the next record in [SubFrm1] after this query has run. I have tried various combinations of refering to the [ItemID] but none of them seem to work. I keep getting error messages.

Am i doing something wrong please.

This is the two lines of code that I have after the RunQuery code:

DoCmd.GoToControl Forms!FrmItems!SubFrm1.Form = ItemID
DoCmd.GoToRecord , ItemID, acNext

Can someone help me please as I am totally stuck.

Thank you,

Kenny [sig][/sig]
 
What error messages are you getting?

I think you also need to put the full reference to the subform in your second line of code as well as the first.

Code:
DoCmd.GoToControl Forms!FrmItems!SubFrm1.Form = ItemID
DoCmd.GoToRecord Forms!FrmItems!SubFrm1.ItemID, acNext

Hope this helps.
Lightning

[sig][/sig]
 
Hi Lightning,

Thanks for your reply, this is a most frustrating problem and I appreciate your help.

I tried your suggestions but I still get the same error message from the same line of code, EG:

Run-time error '450': Wrong number of arguments or invalid property assignment" and the debugger highlites the following line of code in yellow: DoCmd.GoToControl Forms!FrmCDDBImportCDC1!SubFrmCDDBImportCDC2.Form = TrackID

I have included the full code from the button's "OnClick" event below in case there is something else where causing problems.

Any further suggestions??

Thanks again,

Kenny.

****Code Start****
Public Sub Command142_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "QryDataSort"
DoCmd.SetWarnings True
Forms!FrmItems!SubFrm1.Requery
DoCmd.GoToControl Forms!FrmItems!SubFrm1.Form = ItemID
DoCmd.GoToRecord Forms!FrmItems!SubFrm1.ItemID, acNext
End Sub
****Code End**** [sig][/sig]
 
One more suggestion. Try inserting a line of code to explicitly set the focus to the subform

Public Sub Command142_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery "QryDataSort"
DoCmd.SetWarnings True
Forms!FrmItems!SubFrm1.SetFocus
Forms!FrmItems!SubFrm1.Requery
DoCmd.GoToControl Forms!FrmItems!SubFrm1.Form = ItemID
DoCmd.GoToRecord Forms!FrmItems!SubFrm1.ItemID, acNext
End Sub

Hope this helps
Lightning
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top