Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    Apr 2005
    Location
    Plovdiv
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Toolbar function (Access 2000)

    I wanted to build a toolbar function in the form, but after clicking on the button, in the form of an arrow, the error says that no such function exists. Where could the error be ?

    Private Function ToolbarWar()

    Dim cbr As Object
    Dim cbb As Object
    ' msoBarTop = 1
    Set cbr = CommandBars.Add(Name:="ToolbarWar", Position:=1, Temporary:=True)

    Set cbb = cbr.Controls.Add(Type:=1, Temporary:=True)
    With cbb
    .Caption = "My Button"
    .FaceId = 41
    .Width = 60
    .FontSize = 250

    .OnAction = PRR
    End With

    End Function

    Private Function PRR()
    DoCmd.Close
    End Function

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Toolbar function (Access 2000)

    1) The function PRR must be declared as Public. If it is declared as Private, the toolbar button can't find it, since Private items are only available within the module in which they are defined.

    2) You must set the OnAction property of the toolbar to the name of the function as a string:

    .OnAction = "PRR"

    3) FontSize is not a property of a toolbar button.

    4) The new toolbar will be hidden by default. If you want to show it immediately, add a line

    cbr.Visible = True

  3. #3
    2 Star Lounger
    Join Date
    Apr 2005
    Location
    Plovdiv
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Toolbar function (Access 2000)

    Thank Hans, now the button works properly and closes the form.But now another problem appears. When i want to open it, eror Nr 5 appears: invalid procedure call or argument.I have to close the database and enter again in order to open the form . I have the following commands in the activae and deactivate fileds of the form:

    Private Sub Form_Activate()
    ToolbarWar
    DoCmd.ShowToolbar "Toolbarwar", acToolbarYes

    End Sub

    Private Sub Form_Deactivate()
    DoCmd.ShowToolbar "Toolbarwar", acToolbarNo

    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Toolbar function (Access 2000)

    I wouldn't do it like that. I'd remove both instances of

    , Temporary:=True

    from the ToolbarWar function. Then run the function once manually. After that, you don't have to run it any more, unless you have deleted the toolbar and want to recreate it.

    Set the Toolbar property of your form (in the Other tab of the properties window) to ToolbarWar. The toolbar will automatically be displayed when the form is active, and hidden when it isn't. No extra code needed.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •