Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Menu Bar (Commandbar) Help

Status
Not open for further replies.

rjoshi2

Programmer
Sep 10, 2002
110
US
I am trying to create a CommandBar that is able to open forms and tables (using vba in access XP). The code I have written work to some extent. That is the exit button works but the others do not. The other buttons appears in the CommandBar but I can figure out how to make them open the forms or tables that I want. My next question is how due you use OnAction? The reason I ask is if it is not commented out of my current code. Those forms and tables open up when I open my database but the buttons still do not. This current code run in runs in Form_Load of the Switchboard. Any suggestion on how fix these problems would be appreciated.

Thank You
rjoshi2

Here is the code that I have written so far:

Dim custombar As CommandBar
Dim newButton As CommandBarButton
Dim newButton2 As CommandBarButton

Set custombar = Application.CommandBars.Add("Acquistion Log", msoBarBottom, False, True)

Set newButton = custombar.Controls _
.Add(msoControlButton) ', CommandBars("All Forms") _
' .Controls("Main Switchboard").ID)
With newButton
.Caption = "Main Switchboard"
.Parameter = "Main Switchboard"
' .OnAction = OpenForms("Main Switchboard")
If .Type = msoControlButton Then
.Style = msoButtonCaption
End If
End With

Set newButton = custombar.Controls _
.Add(msoControlButton) ', CommandBars("All Tables") _
' .Controls("PSC IT Acquisition Log").ID)
With newButton
.Caption = "PSC IT Acquisition Log"
.Parameter = "PSC IT Acquisition Log"
' .OnAction = OpenTable("PSC IT Acquisition Log")
If .Type = msoControlButton Then
.Style = msoButtonCaption
End If
End With

Set newButton = custombar.Controls _
.Add(msoControlButton) ', CommandBars("All Forms") _
' .Controls("Data Entry").ID)
With newButton
.Caption = "Data Entry"
.Parameter = "Data Entry"
' .OnAction = OpenForms("Data Entry")
If .Type = msoControlButton Then
.Style = msoButtonCaption
End If
End With

Set newButton = custombar.Controls _
.Add(msoControlButton) ', CommandBars("All Forms") _
' .Controls("Edit Object Class").ID)
With newButton
.Caption = "Edit Object Class"
.Parameter = "Edit Object Class"
' .OnAction = OpenForms("Edit Object Class")
If .Type = msoControlButton Then
.Style = msoButtonCaption
End If
End With

Set newButton = custombar.Controls _
.Add(msoControlButton) ', CommandBars("All Forms") _
' .Controls("Search").ID)
With newButton
.Caption = "Search"
.Parameter = "Search"
' .OnAction = OpenForms("Search")
If .Type = msoControlButton Then
.Style = msoButtonCaption
End If
End With

Set newButton = custombar.Controls _
.Add(msoControlButton) ', CommandBars("All Forms") _
' .Controls("Existing Queries and Reports").ID)
With newButton
.Caption = "Existing Queries and Reports"
.Parameter = "Existing Queries and Reports"
' .OnAction = OpenForms("Existing Queries and Reports")
If .Type = msoControlButton Then
.Style = msoButtonCaption
End If
End With

Set newButton2 = custombar.Controls _
.Add(msoControlButton, CommandBars("File") _
.Controls("Exit").ID)
With newButton2
If .Type = msoControlButton Then
.Style = msoButtonCaption
End If
End With

custombar.Visible = True

Function OpenForms(strFormName As String) As Integer
' This function is used in the Click event of command buttons that
' open forms on the Main Switchboard. Using a function is more efficient
' than repeating the same code in multiple event procedures.
On Error GoTo Err_OpenForms

' Open specified form.
DoCmd.OpenForm strFormName

Exit_OpenForms:
Exit Function

Err_OpenForms:
MsgBox Err.Description
Resume Exit_OpenForms

End Function

Function OpenTable(strTableName As String) As Integer
' This function is used in the Click event of command buttons that
' open tabke on the Main Switchboard. Using a function is more efficient
' than repeating the same code in multiple event procedures.
On Error GoTo Err_OpenTable

' Open specified form.
DoCmd.OpenTable strTableName

Exit_OpenTable:
Exit Function

Err_OpenTable:
MsgBox Err.Description
Resume Exit_OpenTable

End Function
 
To make this work (realise its years ago!!) would have to do something like the following:

'call required procedures when buttons clicked
cbcEdit.OnAction = "EditLine"
cbcAdd.OnAction = "AddLine"
cbcRemoveFilter.OnAction = "RemoveFilters"

Where "EditLine" etc is a named macro to open form etc.

Cheers
Gav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top