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

DoCmd Problem 2

Status
Not open for further replies.

rj51cxa

Technical User
Mar 16, 2006
216
GB
I have a form with a Sub Form (SubFrmScores1) which is linked to the form using the field [LngCompetitorNo] in both Child and Master links.

I also have a combo box which is used to select a record in the Master form, using the following code:

Code:
 Private Sub Combo36_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[LngCompetitorNo] = " & Str(Nz(Me![Combo36], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    
    DoCmd.RunMacro "GoToScore7"
End Sub

The last line of the code is the DoCmd with which I am having problems. The Macro is set as follows:

GoToControl SubFrmScores1
GoToControl Score (This is a field in the sub form)

Without the DoCmd coding, the combo box will bring up the correct record every time but the focus does not move to the sub form. With the DoCmd code enabled, the focus moves to the sub form but, occasionally, fails and I receive one or other of the following error messages:

Run-Time error 2105 You can't go to the specified record
Or
Run-Time error 3105 No current record.

In each case, if I click the Debug button the DoCmd coding is highlighted.

The problem appears to be with the coding of the macro but I cannot see any other method of shifting the focus to the sub form.

Any assistance would be much appreciated.
Best Regards
John
 
Replace this:
DoCmd.RunMacro "GoToScore7"
with this:
Me!SubFrmScores1.SetFocus
Me!SubFrmScores1.Form!Score.SetFocus

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV, looks like that has solved the problem. A simple fix but it makes all the difference.

Your help was much appreciated, as always.
Thanks a lot
John

 
Hi again PHV,

Sorry to bother you again but I have found a similar problem to the original one.

The form on which I am working has two sub forms. The combo box code that you gave me moves the focus from the main form to the first sub form but I now need to move the focus from [Score] on the first sub form to [Score] on the second sub form.

I used the same code, with the new sub form number but I get a Run-Time Error 2465 Can't find the field SubFrmScores5 referred to in your expression.

Is it necessary for the focus to be moved back to the main form and then onto the second sub form, or is there a way of doing it direct?

Thanks and regards
John



 
Thanks Remou, you've come to my rescue again. That solved the problem perfectly.

Best Regards
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top