Can't resolve simple code issue

Steven811

Registered User.
Local time
Today, 17:03
Joined
Apr 18, 2004
Messages
133
Hi

I have created my own set of cmd buttons to move through records on a parent and several nested subforms. What I need to do is get them to work from where I position the cursor. I thought this was simple, here's the code I am trying to use. The red text is the bit I can't get to work.


Private Sub cmdNext_Click()
On Error GoTo cmdNext_Click_Err

Me!SetFocus.OnCurrent

DoCmd.GoToRecord , "", acNext

cmdNext_Click_Exit:
Exit Sub

cmdNext_Click_Err:
MsgBox Error$
Resume cmdNext_Click_Exit

End Sub

Thanks

Steven811 - complete novice
 
Hi Steven,

try this:
Code:
Screen.PreviousControl.SetFocus
DoCmd.GoToRecord , "", acNext
 
Code

Hi Bert

The problem I have is that I want one set of nav buttons to work across the forms with the nested subforms. When I move the cursor to a field, I want the nav/cmd buttons to operate the records in that form.

The nav buttons work, but only on the original form on which they were created.

I tried the code that you suggested and still had the same problem.

Rgds

Steven811
 
Steven811 said:
I tried the code that you suggested and still had the same problem.
And what's that problem exactly? What's the errormessage you get?

BTW, the "" in gotorecord must be blank:
Code:
Screen.PreviousControl.SetFocus
DoCmd.GoToRecord , , acNext
 
Error message

Hi Bert

The form is made up of one parent and 4 subforms and I want the one set of nav bars to work on which ever form I have the focus/cursor. I don't get an error message, the buttons only control the one form that they are situated on and I want to be able to use them on the other forms without having to duplicate the buttons on every form, just reposition the cursor.

Hope that's clearer.

Regards

Steven811
 
Ok, I understood already what you want. When I try this:
1. Button on Mainform (with one subform)
2. Code under button:
Code:
Private Sub cmdNext_Click()
  Screen.PreviousControl.SetFocus
  DoCmd.GoToRecord , , acNext
End Sub
3. Set cursor in a textbox on the mainform and click the button -> navigates to next record in the mainform
4. set cursor in a textbos on the subform and click the button -> navigates to next record in the subform

Works fine!
 
Code

Hi Bert

I have recreated the buttons on the parent form and they work fine, thanks.

The only issue I must now resolve is that when I move the focus to the sub form the parent disappears.

Rgds

Steven811
 

Users who are viewing this thread

Back
Top Bottom