access 2003 generate window selectors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • afromanam
    New Member
    • Jan 2008
    • 22

    access 2003 generate window selectors

    Hi

    I've been setting up a custom toolbar on start up for the application via VBA code.

    I've generated, for the custom menu bar, the drop-down menus File, Edit, Window and Help and successfully added controls to each of them except for Window. I can't seem to add the funcitionality where upon opening a form it will add itself to the Window menu as an item so when it has lost focus it can be selected again.

    I looped through a database default menu bar and figured out that the menu item that selects a window is of type 1, and id 830, the caption of the menu item (control) is &# Window Name

    On the customized db I used the:

    Code:
       Set cbcCutomMenuButton = cbcCutomMenu.Controls.Add(1,830)
       With cbcCutomMenuButton
        .Caption = "&1 Main Menu"
       End With
    If I try to set the id as 830 it yields an Add method error, If i don't, it doesn't do nothing upon clicking it.

    If I generated a new application toolbar, I should be adding, for each form that is opened, a menu item into the drop down menu Window in the onopen event of the form?, with the control's onaction property set to focus the form, and on the onclose event to the form i should remove the menu item?

    Is there any way to emulate the default toolbar behaviour?

    Please advise, note that manually adding a menu item is not possible due to technical reasons (and because since I've been going at this thing for 3 hours without luck, and also because of my curiosity if this can be done :))

    Thanks in advance and best regards,

    Afro
    Last edited by afromanam; Dec 11 '09, 12:31 AM. Reason: corrected the code, to put the id in the add method, where it fails
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Why not Hide the Original Custom Command Bar, Clone it whenever appropriate along with its Controls, then make it Visible, positioning it at the Top of the Window. All 'Opened' Windows will then be Visible in the Drop Down Window Menu. I executed this code against the Northwind Custom Menu Bar in the Sample Database and, although it is a rather rogue solution, it does work. Simply create a Function encapsulating the code, then call it whenever needed. I'm not really sure that this can be done in any other fashion. Good Luck.
    Code:
    Dim mbr As CommandBar
    Dim cbrCopy As CommandBar
    Dim cbr As CommandBarControl
    Dim ctl As CommandBarControl
    Dim cbrCtl As CommandBarControl
    Dim intOrigCount As Integer
    
    'Customize with your own Name
    Const strCLONE_TBR_NAME As String = "Window_2"
    
    Application.CommandBars("NorthwindCustomMenuBar").Visible = False
        
    Set mbr = CommandBars("NorthwindCustomMenuBar")
    Set cbr = mbr.Controls("Window")
    
    'DELETE if it exists to avoid ERROR
    Application.CommandBars(strCLONE_TBR_NAME).Delete
    
    'Count of Controls on Original Command Bar
    intOrigCount = mbr.Controls.Count
        
    'ADD the New Command Bar to the Collection, make Visible
    Set cbrCopy = CommandBars.Add(strCLONE_TBR_NAME)
        cbrCopy.Visible = True
    
    'Copy all Controls to the Cloned Command Bar
    For Each cbrCtl In mbr.Controls
      cbrCtl.Copy cbrCopy
    Next cbrCtl
    
    'Position at Top of Window
    cbrCopy.Position = msoBarTop

    Comment

    • afromanam
      New Member
      • Jan 2008
      • 22

      #3
      Hi

      Thanks for the reply, will look into that.

      Unfortunately my weekend didn't unfold as planned so I couldn't test this at home. I managed to write a couple of sub's which add the window name to the custom window menu on the onopen event, with the onaction property set to a generic fnFocusForm(frm name), and remove the button from the custom Window Menu it on the onclose event.

      Feels like I'll have even more control over what the users are seeing.

      I will try your approach later, I'd just have to loop thru the default Window Menu Window Selectors (that's what I call 'em, don't know if that's their right name) to see if I want the user to see that particular window.

      Regards,

      Afro

      Comment

      Working...