Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Center content on form dynamically 2

Status
Not open for further replies.

ptuck

MIS
Aug 8, 2003
130
US
My form opens maximized which is what I want. However, depending on the resolution and/or monitor the content on the form is not always centered. Is there an easy way to have the content on the form to automatically center to the size of the form?

Thanks for the help..
Paul
 
Can you give us an example of how you are calling the function?
 
Thanks for the reply. This is how I am calling the function.

***CODE START***
Private Sub Form_Load()

DoCmd.Maximize
CenterForm Me.Name

End Sub
***CODE END***
 
If you haven't already done so, create a new module and copy and paste the code from my 1st post (and don't forget the modification I made in my 2nd post)). By default, it should be public, but it wouldn't hurt to declare it as public.
 
FancyPrairie, I am trying to implent your code, and it is not clear what type of module to create. I first tried a normal module, and got the same response as Progressiverookie, tried adding a "Public" before the function name, same result. Then I tried to add a class module and I get "invalid use of property". I have tried using Me.Name as well as explicitly nameing the form. Did anyone get this to work?
Thanks, Ken.

- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
 
I'm not sure what you're doing wrong. This is what I just did to test it...From the database window I selected Module and then New and then copied and pasted the code via my 1st post (with the change indicated in my second post). I then created a new form and put a couple of text boxes on the form. In the OnLoad Event of the form, I added the following code:

DoCmd.Maximize
CenterForm Me.Name

When I opened the form, everything was centered correctly.
 
Perhaps it is my form. I have a tabbed control with three tabs. Each tab has multiple controls, but the main form just has the tab control. I did the same as you, new module, pasted the code, made the change, saved the module and used the same call. I'm stumped.
Ken

- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
 
I still don't get it. I just created a form with just the tab control with 3 tabs and text boxes in each of the tab pages. Everything worked ok. You might check over the properties of your form. You don't have it set as a popup do you?

Try this. Put a command button on your form and in the onclick event call the function CenterForm... However, prior to calling it, set a breakpoint on that line and then step thru it via debug. (In one of my previous post I explained how to use debug...if you haven't used it before).
 
I found the problem, I named the module the same as the function. That doesn't work. I changed the name and it works great. Now I need to stop it from restoring the switchboard from maximized when I close an opened report. Think I saw something about that above. Thanks, Ken.

- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
 
OK, I tried putting my DoCmd.Maximize in the On Activate event, but now I lose my centering. Very strange. Should I move the centerform call to the same event? It was working when I had them both in the on load event. I assume I need to maximize before I center? Which one comes first?
Ken

- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
 
I think this was the problem I was having with the center function as well.
 
I put both in the on activate event and it seems to work fine except my switchboard relocates itself farther to the right after I open and close any other form. I'm not sure why it is doing that.
Ken

- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
 
That is pretty much what mine is doing. Except any time I access a form more than once it moves it over to the right. In other words, I open the app click on form1 then close form1 and open form2 then close form2 and open form1 again and it has shifted further to the right.
 
I was going over the code and there is nothing to handle an image. I have an image that is the farthest left on my switchboard. I tried using Centerform Me.Name, "image22"
But it broke Access with a mismatch error.
Ken

- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
 
Same behavior here, maybe I tried to put it in the got focus event just on my switchboard, but after that it not only moved to the right, it became small.
Ken

- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
 
First, notice my disclaimier in my first post (Here's some code I put together real quick, but haven't had time to clean it up (or check for all control possibilities).
Second, you don't have to pass the 2nd argument because the function will figure out the farthest control on the left for you. Also, note that the 2nd argument is the value of the left property. For example,

CenterForm Me.name, Image1.Left
 
OK, I saw your caveat, no problem. I missed that .left part, but it did not solve the problem of the switchboard migrating right. It's probably because it's already open and stays open in the background. If someone finds the answer please post it. Thanks, Ken.

- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top