VVBA Toolbar trouble!

deanwat

New member
Local time
Today, 01:01
Joined
Nov 14, 2007
Messages
5
I am trying to build a custom toolbar with two buttons that will open two different reports. I think I have it all but the OnAction part can someone help me. Here is what I have so far.

Code:
Sub AddNewCB1()
    Dim CBar As CommandBar, CBarCtl As CommandBarControl
    Dim strReport As String
    Dim strReport1 As String
    On Error GoTo AddNewCB_Err
    
    strReport = "rptPurchase"
    strReport1 = "rptInventory"
    
    CommandBars("Report Bar").Delete
    Set CBar = CommandBars.Add(Name:="Report Bar", Position:= _
    msoBarFloating)
    CBar.Visible = True
    
    Set CBarCtl = CBar.Controls.Add(Type:=msoControlButton)
    With CBarCtl
        .Caption = "Purchase "
        .Style = msoButtonCaption
        .OnAction = "DoCmd.OpenReport strReport, acViewPreview"
    End With
    
    Set CBarCtl = CBar.Controls.Add(Type:=msoControlButton)
    With CBarCtl
        .Caption = "Inventory "
        .Style = msoButtonCaption
        .OnAction = "DoCmd.OpenReport strReport1, acViewPreview"
        
    End With
    Exit Sub
AddNewCB_Err:
    MsgBox "error " & Err.Number & vbCr & Err.Description
    Exit Sub
    CommandBars("Report Bar").Delete
End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom