• Adding menu items on the fly using VBA

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Adding menu items on the fly using VBA

    Author
    Topic
    #373255

    I have several forms opened at one time (from 1-15)
    I can get a list of opened forms no problem but I want to list them as menu items that can be selected.
    Currently I create a table of opened forms then diplay them on a form that allows a selected form to become the active form when double clicked.
    In the 5 books I have beside me I have found no reference to how or if I can change the menu on the fly.

    Viewing 2 reply threads
    Author
    Replies
    • #599252

      Check your reference books again for using a Callback Function to fill a listbox. It is rather complicated, and I really don’t understand how it works (I can use it only by copying an existing function and making changes). Good luck!

      • #599780

        Hi Mark,
        Why couldn’t you just use code sorta’ like the test code I put in my reply to Bawn?
        Gwenda

        • #599835

          The .AddItem method is not available in all versions of Access, and I’m not sure if there are limits to how many rows can be added this way. That is, if the rowsource is a value list, then there is a limit of something like 2000 characters; which may or may not be a problem in certain circumstances.

          Also, the .ListIndex property is read-only.

          • #599860

            I haven’t tried using the .AddItem method on a commandbar combobox, but I suspect it may work there because the commandbars are actually Office objects rather than Access objects. Access comboboxes, of course, don’t have an AddItem method at all.

            • #600129

              Didn’t I see where .AddItem is now available for combo/listboxes in Access2002?

            • #600144

              I thought you were talking about 2000? I believe you can use the MSForms comboboxes in AXP, but I’ll have to check at work and see if it’s there in regular Access combo and listboxes. shrug

    • #599315

      Hi Bawn,
      In online help is code to populate a CommandBarCombox Object which I pasted below. Then couldn’t you cycle through the collection of open forms and populate the combobox with their names?

      Set combo = CommandBars(“Custom”).Controls(2)
      With combo
      .AddItem “First Item”, 1
      .AddItem “Second Item”, 2
      .DropDownLines = 3
      .DropDownWidth = 75
      .ListIndex = 0
      End With

      Gwenda

    • #599769

      Hi Bawn … I fooled around with this a bit and am able to create a custom toolbar and populate with names of open forms:

      Sub test()
      Dim menubar As CommandBar
      Dim newcombo As CommandBarComboBox
      Dim frm As Form

      Set menubar = CommandBars.Add _
      (Name:=”Custom2″, Position:=msoBarFloating, menubar:=True)
      With menubar
      .Protection = msoBarNoMove
      .Visible = True
      End With

      Set newcombo = CommandBars(“Custom2”).Controls _
      .Add(Type:=msoControlComboBox)
      For Each frm In Forms
      With newcombo
      .AddItem frm.Name
      .OnAction = “switch to form” ‘would have to call a function here to switch to the form you want
      End With
      Next frm
      End Sub

    Viewing 2 reply threads
    Reply To: Adding menu items on the fly using VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: