Article ID: 142187
Article Last Modified on 10/11/2006
Caption: Toolbar
ShortcutMenu: No
ScrollBars: Neither
RecordSelectors: No
NavigationButtons: No
PopUp: Yes
BorderStyle: Dialog
Min Max Buttons: None
Categories Actions
--------------------------------------------
Record Operations Save Record
Record Operations Delete Record
Record Operations Undo Record
Record Navigation Go to First Record
Record Navigation Go to Previous Record
Record Navigation Go to Next Record
Record Navigation Go to Last Record
Record Operations Add New Record
Option Explicit
Function ActivateToolbarForm ()
On Error Resume Next
Forms(Me.Tag).SetFocus
If Err Then
ActivateToolbarForm = False
Else
ActivateToolbarForm = True
End If
End Function
This function will be used to reactivate the form that the toolbar is
floating on so that the chosen operation is performed on that form
rather than against the Toolbar form itself.
If ActivateToolbarForm() = False Then Exit Sub
The code for the Search button might look as follows:
Sub Command0_Click()
If ActivateToolbarForm() = False Then Exit Sub
On Error GoTo Err_Command0_Click
Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub
This code ensures that the form the toolbar is floating on is selected
for the chosen operation.
Option Explicit
Sub SetToolbarForm (F As Form)
If IsLoaded("Toolbar") Then Forms![Toolbar].Tag = F.Name
End Sub
The SetToolbarForm subroutine uses the IsLoaded() function that is in
the Utility Functions module of Northwind.mdb. You can copy this
function into your database.
SetToolbarForm Me
For this example, add the line of code above to the OnActivate property
of the Employees and Customers forms. To do so, follow these steps:
Sub Form_Activate ()
SetToolbarForm Me
End Sub
Sub Form_Load ()
DoCmd.OpenForm "Toolbar"
End Sub
Sub Form_Unload (Cancel As Integer)
DoCmd.Close ACFORM, "Toolbar"
End Sub
DoCmd.MoveSize 0, 0113304 ACC2: How to Create a Custom Toolbar Using a Form
Keywords: kbhowto kbprogramming kbusage KB142187