DoCmd.GoToRecord

stevenblanc

Registered User.
Local time
Yesterday, 16:54
Joined
Jun 27, 2011
Messages
103
Hi folks,

So I have the following code:

Code:
Private Sub lstGuidelines_AfterUpdate()
    DoCmd.GoToRecord acDataForm, Me.Form.Name, acGoTo, Me.Form.lstGuidelines
End Sub

Works like a charm when I load up the form. However, when the same form is embedded into my main interface form I get the following error:

Run-time error '2489':

The object 'frmSubGuidelines' isn't open.

Any idea how I resolve this issue?


Steven
 
Sean,

I've had that open for the last hour working all of my other form reference bugs out.

However, in this case that table recommends from Subform1 to Subform1: me.recordsource

which in my case is: me.form.name as both the listbox and the record information exist on the subform.
 
Code:
Private Sub lstGuidelines_AfterUpdate()
    DoCmd.GoToRecord acDataForm, Me.Form.Name, acGoTo, Me.Form.lstGuidelines
End Sub

In the above code sample that you posted earlier, the form reference is;

Me.Form.Name

which will return "frmSubGuidlines" if that is the name of your form.

(BTW - you don't really need the .Form here, Me.Name will return the same thing - just FYI)

Now, as soon as you place that form (frmSubGuidlines) inside another form then -

Me.Form.Name

- will no longer work. You now need to include a reference to the Parent form and the Subform Control that frmSubGuidlines was just placed in. Keep in mind that the name of the Subform Control may or may not be the same as the name of the sub form (in this case frmSubGuidlines) that is placed within it.

So, if we assume that the Subform Control and the sub form itself have the same name, then your code would need to be modified something like;

Code:
Private Sub lstGuidelines_AfterUpdate()
    DoCmd.GoToRecord acDataForm, Forms!YourMainForm!sfrmSubGuidlines.Form, acGoTo, Me.Form.lstGuidelines
End Sub
 
That results in an error regarding the wrong data type as its supposed to be the name of the form. Alternative using .Name instead of .Form returns to the original issue. Thus getting us nowhere.

Code:
    DoCmd.GoToRecord acDataForm, Forms!frmMain!frmSubGuidelines, acGoTo, Me.Form.lstGuidelines
 
Problem solved:

Got rid of all form references:

Code:
 Private Sub lstGuidelines_AfterUpdate()
    DoCmd.GoToRecord , , acGoTo, Me.Form.lstGuidelines
End Sub
 

Users who are viewing this thread

Back
Top Bottom