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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coding GoToRecord on a subform? 1

Status
Not open for further replies.

markvan

Technical User
Sep 12, 2001
37
AU
I have been stuffing around for hours, trying to goto a record on a subform, from a report.

Form is called frm_NAV
Subform is called frm_reports
The field I want to go to is ReportID.

I keep getting "OBJECT NOT OPEN" errors.
Suggestions Oh gurus? Mark Van
EZ-PC Help
 
Try This:

Forms![frm_Nav].[frm_Reports]![ReportID].SetFocus

Hope this works - Shane
 
You are flitting between terms and meaning - probobly induced by the hours of frustrated activity working on the problem.

If you just want to set the focus to the CONTROL called ReportID that is on the subform then you need

Forms!frm_Nav!frm_Reports.Form!ReportID.SetFocus

This is made up of
Forms generic keywork
FormName of top level form
ControlName of the subFormControl ( Not necessarily the same as the subForm's Name )
Form keyword - to tell the system to treat the control as a form in it's own right
Control Name on the subform
SetFocus - finally the 'do the business' bit


HOWEVER, If you want to go to a specific record on the subform where a control on the subform matches the value of the control [ReportId] on the main form then you'll need:-

Forms!frm_Nav!frm_Reports.Form!subFormControlName.SetFocus
Docmd.FindRecord = ReportId

There is a potential risk here of confusing things if the control on the main form is the same name as the control on the subForm.
To avoid confusing the system use
Docmd.FindRecord = Forms!frm_Nav!ReportId

But even better - to avoid confusing anyone reading the code later - call the control on the subForm something different.



'ope-that-'elps.

G LS


 
Thanks guys, you guys pointed me in the right direction.
It's amazing what a good sleep and a bit of Tek-Tip help can make.

Here is the code that works for me, in case it can help anyone else.

Private Sub Report_Close()
On Error GoTo Err_Command193_Click

Dim stLinkCriteria As String
Dim mainNAV As String

mainNAV = "frm_NAV"
stLinkCriteria = Me![ReportID] 'grabs reportID from the report

DoCmd.OpenForm mainNAV, acNormal, , , acFormEdit, acWindowNormal 'Opens main form
Forms![frm_NAV]![Term Progress Reports].SetFocus ' focus on tab
Forms!frm_NAV!tbl_reports.Form!ReportID.SetFocus 'focus on ID field
'Sub reports control name is different to sub reports actual name
DoCmd.FindRecord stLinkCriteria 'finds the record
Forms!frm_NAV!tbl_reports.Form![Back Cover].SetFocus
'focus on tab inside correct record

Exit_Command193_Click:
Exit Sub

Err_Command193_Click:
MsgBox Err.Description
Resume Exit_Command193_Click
End Sub Mark Van
EZ-PC Help
 
Hey guys, I have simliar a problem to this one. I want to have a new button on a sub form that when clicked will move form to a new record. When I use the 'DoCmd.GotoRecord' command it gives me the error '2489 object not open'. I have tried to set focus to the sub form ,but it does not work.

Can you please help?

Clayton T. Paige
claytonpaige@yahoo.ca

Programmer Extraordinaire

========================================================

"Who is General Failure? and Why is he reading my disk drive?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top