Full Version: GoToRecord - on a subform?
UtterAccess Forums > Microsoft® Access > Access Forms
One subform has a routine that adds a record that shows up on another subform of the same parent form. At the end of the routine, I'd like the new record on the other subform to be the current record.
one of the code I've tried works. Either the GoToRecord method affects the main form (even if I use SetFocus on the subform) or if I try to specify the subform in the GoToRecord method, I get an error saying it's not open.
Ready to give up on this unless someone has a clue.
I use this and it works fine. 'sfm' is the name of my subform control. It refreshes the subform, because the task
added was selected from a list control on the main form. Next it finds the newest task added to the current
project and sets the focus to the Days textbox, so the user can enter the number of days for this task. -
    pkTask = DMax("[PK_TASK]", "TASK", "[PK_PROJECT]=" & Me.PK_PROJECT)
    'Position record pointers
    Me.sfm.Form.Recordset.FindFirst "[PK_TASK] = " & pkTask
    Me.sfm.Form.F_DAYS.SetFocus 'goto the Days textbox
Are you aware that setting the focus to a control on a SubForm is a two step process?
From the Main form it would be:
Me.SubFormControlName.SetFocus '-- Set Focus to the SubFormControl 1st
Me.SubFormControlName.Form!txtSerialNumber.SetFocus '-- Set Focus to the Control on Subform
DoCmd.RunCommand acCmdRecordsGoToLast '-- And move to the new record
Thanks both of you - looks like there's a way.
So, rg, I didn't know I had to set focus first on the subform control; thanks for that.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.