Results 1 to 3 of 3

Thread: [RESOLVED] Remove item from menu and add code to Dynamic menu items

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Resolved [RESOLVED] Remove item from menu and add code to Dynamic menu items

    Hi.
    I build my menu dynamically from a recordset.
    Code:
    While Not listTypes.EOF               
        Load mnufiles(mnufiles.UBound + 1)
        With mnufiles(mnufiles.UBound)
            .Caption = listTypes.Fields(1) 
            .Enabled = True
            .Visible = True
            .Checked = True
        End With
        listTypes.MoveNext
    Wend
    What happens is that i've got this menu, by default with one item (the first).
    I wan't to remove it because it doesn't matter anymore after loading fields from DB.
    How can I do this?

    Another question:
    How do I associate code to the dynamically generated menu items?
    Thanks.
    Last edited by RS_Arm; Apr 17th, 2007 at 04:07 AM.

  2. #2
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Remove item from menu and add code to Dynamic menu items

    As for unloading the placeholder menu item, the help file says you can't. But you can hide it:

    mnufiles(0).Visible = False

    As a (better) alternative, when creating the menu in code, have it check to see if this is the first item you're adding. If so, instead of creating another menu item, just use the placeholder item. (And skip incrementing your index counter for that one, of course.)

    Re-using menu items is faster than unloading/reloading them all from scratch anytime the underlying data changes.

    As for the code, it works just like any other menu. In your form you have:
    Code:
    Private Sub mnufiles_Click(Index As Integer)
        ' Do your thing based on the Index
    End Sub
    This sub fires when any of the menu items are clicked.
    Last edited by Ellis Dee; Apr 17th, 2007 at 04:24 AM.

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Remove item from menu and add code to Dynamic menu items

    Thank you very much.
    That worked.

Posting Permissions

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



Click Here to Expand Forum to Full Width