Solved

Setting initial position for a custom menu / toolbar

Posted on 1998-01-27
10
666 Views
Last Modified: 2008-06-19
I have created a toolbar and menu for a form and report I have made using Access '97.  The custom toolbars seem very powerful, since I can launch macros and VBA functions from them.  However, when I enter my form or report, the toolbar or menu is just sitting there.  Sure, I can move it and reposition and resize, but how can I code it so that it is initally docked at the top?  Is this possible?  I will be exporting this project as a stand-alone, so I am wanting, when they click on the "Create Report" option in my form, to show a report with a single menu bar above which I have created, which has various preferences.  I do not want a floating menu or toolbar.  I want it initally positioned to my liking.  Thanks!
0
Comment
Question by:mitchell042997
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 8

Expert Comment

by:Kobe_Lenjou
ID: 1966771
Isn't there an 'align' property wich you can set to TOP?
0
 
LVL 2

Author Comment

by:mitchell042997
ID: 1966772
I don't think so.  WHere is this align property you speak of?  Is it in the form properties, or the custom toolbar properties?  Thanks for any help!
0
 
LVL 5

Expert Comment

by:cekman
ID: 1966773
Try something like this -which I got from Access 97 menubar help:
This does more than you want - but shows how to dock.....

Adding menu bars at run time

When you add a menu bar to an application at run time, you use the Add method for the CommandBars collection and specify True for the MenuBar argument. The following example adds a menu bar that cannot be moved. The example also docks this menu bar along the right side of the application window. The new menu bar becomes active whenever the user presses the ALT key.

Set menubar = CommandBars.Add _
    (Name:="mBar", Position:=msoBarRight, MenuBar:=True)
With menubar
    .Protection = msoBarNoMove
    .Visible = True
End With
0
 
LVL 2

Author Comment

by:mitchell042997
ID: 1966774
I already read that in the help files.  But I couldn't get it to work.  If you can code a program which does what I want it to do, post the source code, and I will award you the points.  But to just rehash something out of the help files.  A two year old could do that.
0
 
LVL 12

Accepted Solution

by:
Trygve earned 100 total points
ID: 1966775
Try this:

CommandBars("Menu Bar").Visible = True ' Mine kept disapearing

CommandBars("PIMSInfoCentre").Visible = True
With CommandBars("The name of your command bar")
  .Position = msoBarTop
  .Protection = msoBarNoChangeDock + msoBarNoChangeVisible + msoBarNoMove + msoBarNoResize
  .Visible = True
End With

These lines located a predefined bar at the top at didn't allow me to play with it (move, remove etc.)

Hope this helps !
Trygve
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 5

Expert Comment

by:cekman
ID: 1966776
<<I already read that in the help files. But I couldn't get it to work. If you can code a program which does what I want it to do, post the source code, and I will award you the points. But to just rehash something out of the help files. A two year old could do that. >>

I don't usually respond to comments like this but.....

Where in your original question does it say that you tried this command - the MAJORITY of the questions asked here could be solved by people pressing F1. I attempted to answer your question - which specifically asked about docking - which is specifically addressed in the example. I'm sorry it didn't work for you - but a simple - thanks anyway would have sufficed. Please - in the future - don't refer to someone who is sincerely trying to help you to solve a problem - as a 2-year old. It's not (IMO) professional.

It also would be VERY helpful if you would have included the code you tried - and stated exactly what it did/didn't do for you - along with any possible error messages.

I hope Trygve has given you an anser you can use.
CEkman
0
 
LVL 2

Author Comment

by:mitchell042997
ID: 1966777
Where would you place that code that you presented me with?  Would you place it in a function in a global module, or could it go in the Form's OnLoad Event handler?  This menu bar is just for the form, if that helps any.  Also, is there any add-ins I need to install?  Is this a macro, or VBA code.  I ask, because trying similar code in VBA has given me errors, it doesn't recognize the CommandBars object.  (I am using Access '97, for reference's sake.)  Thank you.
0
 
LVL 2

Author Comment

by:mitchell042997
ID: 1966778
Sorry to snap, CEckman, but I have had so many people lock up questions I've posted with half guesses and documentation quotation.  For example, I have asked questions before and gotten answers like, "Well, I guess you could try doing this:" and then they would cut and paste out of the help files from a category in the help files which matched my question.

Sorry to react so vehemently.  It's just frustrating (and to no fault of your own), because I do spend a lot of time before posting here, and then to see in email that the question has been answered, and then to have that answer be a snippet out of the help files I have already read over ten times...  Oh well, again, sorry for the trite response.
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1966779
I put the code in the OnOpen Event for the form. I have rewritten it a bit, because my initial proposal include parts from my test.

CommandBars("Menu Bar").Visible = True

With CommandBars("Toolbox") ' Toolbox menubar used as example
  .Visible = True
  .Position = msobartop ' 1
  .Protection = msoBarNoChangeDock + msoBarNoChangeVisible + msoBarNoMove + msoBarNoResize
  .Visible = True
End With

This worked without error in my test. If you get any errors, regarding the CommandBars collection or others, please let me know.
0
 
LVL 2

Author Comment

by:mitchell042997
ID: 1966780
It worked.  There was one thing, though, that if you get asked this question or one similar, you may want to add.  You need to go to Tools / References in the code editor and add Microsoft Office Tools 8.0.

Thanks for your help.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now