Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Jul 2002
    Location
    BC Canada
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding menu items on the fly using VBA

    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.

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Adding menu items on the fly using VBA

    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!
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Star Lounger
    Join Date
    Feb 2001
    Location
    Vancouver, BC, Br. Columbia, Canada
    Posts
    96
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding menu items on the fly using VBA

    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

  4. #4
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding menu items on the fly using VBA

    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

  5. #5
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    vancouver, BC, Br. Columbia
    Posts
    109
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Adding menu items on the fly using VBA

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

  6. #6
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Adding menu items on the fly using VBA

    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.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Adding menu items on the fly using VBA

    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.
    Charlotte

  8. #8
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Adding menu items on the fly using VBA

    Didn't I see where .AddItem is now available for combo/listboxes in Access2002?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  9. #9
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Adding menu items on the fly using VBA

    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. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

Posting Permissions

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