R
Robert Neville
I am having some trouble with some old code revolving around custom
form navigation buttons. My main form has a sub-form with these custom
navigation buttons. In other words, the code should be modular and
work across forms and sub-forms. My previous code was taken from the
Access Expert Solutions 97 (Leszynski) many years ago. As my database
became more complex with multiple sub-forms and intricate combo boxes,
the code faltered.
Some excerpts from the code follow. These areas may point to some of
the idiosyncrasies. Error handling has been excludes for this post.
Private Sub btnNext_Click()
Call FrmFocusSave(Screen.PreviousControl)
Call FrmNavGotoNext(Screen.ActiveForm)
Call FrmFocusRestore
End Sub
Public Sub FrmFocusSave(ctl As Control)
' Purpose: Save a pointer to the active control
Set mctlFocusSave = ctl ' Save the pointer
End Sub
Public Sub FrmNavGotoNext(rfrm As Form)
' Purpose: Goto next record in form recordset
If rfrm.mtdValidate Then ' Record is valid
If Not FrmNavIsLast(rfrm) Then
rfrm.SetFocus ' Just to be sure
Application.RunCommand acCmdRecordsGoToNext
End If
End If
End Sub
Screen.ActiveForm seems to have issues when placed behind the
navigation buttons of a sub-form. The Screen.ActiveForm grabs the
main form (not the sub-form). Screen.PreviousControl may have a
similar effect. The screen method does not aid the debugging process
since the debugging window has focus not a form. Maybe, another
approach exist. Please let me know another approach to custom
navigation buttons. In addition, how does acquire the previous
control and active form in a bulletproof manner.
The sub-form may have additional issues, but I save the specifics for
the next post. Just keep in mind that each form may be open by another
form in dialog mode. So I am continually jumping from one form to
another. The custom navigation button should allow for this usage.
form navigation buttons. My main form has a sub-form with these custom
navigation buttons. In other words, the code should be modular and
work across forms and sub-forms. My previous code was taken from the
Access Expert Solutions 97 (Leszynski) many years ago. As my database
became more complex with multiple sub-forms and intricate combo boxes,
the code faltered.
Some excerpts from the code follow. These areas may point to some of
the idiosyncrasies. Error handling has been excludes for this post.
Private Sub btnNext_Click()
Call FrmFocusSave(Screen.PreviousControl)
Call FrmNavGotoNext(Screen.ActiveForm)
Call FrmFocusRestore
End Sub
Public Sub FrmFocusSave(ctl As Control)
' Purpose: Save a pointer to the active control
Set mctlFocusSave = ctl ' Save the pointer
End Sub
Public Sub FrmNavGotoNext(rfrm As Form)
' Purpose: Goto next record in form recordset
If rfrm.mtdValidate Then ' Record is valid
If Not FrmNavIsLast(rfrm) Then
rfrm.SetFocus ' Just to be sure
Application.RunCommand acCmdRecordsGoToNext
End If
End If
End Sub
Screen.ActiveForm seems to have issues when placed behind the
navigation buttons of a sub-form. The Screen.ActiveForm grabs the
main form (not the sub-form). Screen.PreviousControl may have a
similar effect. The screen method does not aid the debugging process
since the debugging window has focus not a form. Maybe, another
approach exist. Please let me know another approach to custom
navigation buttons. In addition, how does acquire the previous
control and active form in a bulletproof manner.
The sub-form may have additional issues, but I save the specifics for
the next post. Just keep in mind that each form may be open by another
form in dialog mode. So I am continually jumping from one form to
another. The custom navigation button should allow for this usage.