Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
Create a custom toolbar in Access
The first thing to do is to create the toolbar as a CommandBar object:
Set myBar = CommandBars.Add(Name:="Customer", _
.Controls.Add Type:=msoControlButton, Id:=539
.Controls.Add Type:=msoControlButton, Id:=4
.Controls.Add Type:=msoControlButton, Id:=644
.Visible = True
Theproperty is set True to define this as a temporary toolbar. It will disappear when the database is closed. This property defaults to False and any toolbar that you create will persist and reappear the next time that you open the database. If you do use a permanent toolbar then you must add error-handling code to ensure that you do not try to create it a second time.
A command bar can hold several different types of control and theparameter here declares that we are adding three command buttons. The parameter defines the icon that will appear on these buttons and the action that the button will perform if we do not override it later. Set an Id of 1 if you want a button with no icon.
Define the buttons
Each button on the toolbar is a member of the Controls collection of the CommandBar. This fragment of code defines the third button on the toolbar:
.Style = msoButtonIconAndCaption
.Caption = "Delete Customer"
.OnAction = "=DeleteCustomer()"
.TooltipText = "Delete all records of this customer"
Theproperty is set to show an icon and some text. You can also choose or to show an icon or some text alone.
Theproperty defines the action that must be performed when this button is clicked. In this example it calls a method of the form.
Show and hide a toolbar
Use theand properties of the CommandBar object to control whether or not the user can see and operate the buttons on the toolbar.
Removing a toolbar
This code in the form'sevent removes the toolbar from the collection of CommandBars. There is always the possibility that the user might have closed the toolbar manually so we have to work around this possible error.
'-- already deleted this toolbar.
On Error Resume Next