Solved

Setting initial position for a custom menu / toolbar

Posted on 1998-01-27
10
667 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

785 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