By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,940 Members | 611 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,940 IT Pros & Developers. It's quick & easy.

Make forms show up in middle of screen

100+
P: 443
Why is it that on laptops with wide screens that my application screens show up on the right side of the screen and the user has to drag the screen into the middle. Is there a way to make the screen always show up in the middle of the screen?
Thanks for any help.
Feb 10 '09 #1
Share this Question
Share on Google+
19 Replies


Expert 100+
P: 1,287
I've noticed this too when working on my frontend on 2 monitors. Even though my forms are all set to centered, when I compile and distribute it, users have forms open up way off center, maybe relative to where I have them while developing. I think it has helped to make sure I open Acess in a regular size window, then open the forms and make sure they are centered there before I make the accdr (or mde). It seems really inconsistent though, and I haven't collected too much evidence.
Feb 10 '09 #2

ADezii
Expert 5K+
P: 8,623
@CD Tom
You can always make sure that Forms always show up in the 'Middle' of the Screen regardless of Screen Resolution or other factors, but the code is complex and involves judicious use of the API. If you are interested, I'll create a Demo DB that will illustrate this functionality for you.
Feb 10 '09 #3

100+
P: 443
That would be great, If you can just give me the code I can probable figure it out, unless it's easier doing the demo DB. Thanks
Feb 10 '09 #4

ADezii
Expert 5K+
P: 8,623
@CD Tom
  1. Download the Attachment, it will make things a little easier.
  2. Within your Database, Import the FormInfo Class from the Demo Database. Almost the entire code functionality is encapsulated within this Class.
  3. In the General Declarations of your Form, declare a variable to represent the FormInfo Class, as in:
    Expand|Select|Wrap|Line Numbers
    1. Private mfi As FormInfo
  4. In the Form's Load() Event, create a New Instance of the Class, set its Form Property to the Form where code is currently executing (Me), then Call the Center Method of the Class to Center the Form.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Load()
    2.   Set mfi = New FormInfo
    3.   Set mfi.Form = Me
    4.     mfi.Center
    5. End Sub
  5. Reposition the Form, and Click on the Command Button at any time to Re-Center it on the Screen.
  6. Disregard any related Properties, Methods, and Declarations from the FormInfo Class if they are not needed.
Feb 11 '09 #5

100+
P: 443
Thanks I'll let you know when I get everything working.
Feb 11 '09 #6

100+
P: 443
I've just got around to trying this and have a couple of errors. When I try and compile the program I get a error on Private mfi as formInfo the message is "Compile Error: A module is not a valid type" not to sure what to do next.
Feb 16 '09 #7

100+
P: 443
I was able to fix the first error but now I'm getting an on the the following line: .STATE = Val(Getsetting(appName, strName, adhcState, me.WindowState)) when I try and compile get an error on WindowState Compiler error: Method or data member not found" Got any ideas what's causing this.
Thanks, the program will run and the form does allign but the error comes up when I compile.
I ran the compile on your database and get the same error. Are we missing a ref or something?
Feb 17 '09 #8

ADezii
Expert 5K+
P: 8,623
@CD Tom
I'll look into it as soon as I get a chance.
Feb 17 '09 #9

ADezii
Expert 5K+
P: 8,623
@ADezii
WindowState is a Property of the FormInfo Class as evidenced by a pair of Property Let/Get Procedures contained within this Class. It appears as though a Variable has not been Declared as FormInfo, or that it has not properly been instantiated. Double-Check Steps 3 and 4 in Post #5, and make sure these Lines of Code are present exactly where they should be. Get back to me on this.
Feb 17 '09 #10

100+
P: 443
I've doubled checked everything and when I compile I still get the "Compile error Method or Data member not found. When I compile your database I get the same error.
Feb 17 '09 #11

ADezii
Expert 5K+
P: 8,623
@CD Tom
I'll call in some of my colleagues in on this one. If the problem can't be resolved, can you E-Mail me a Copy of your Database so that I may have a look at it?
Feb 17 '09 #12

Expert Mod 2.5K+
P: 2,545
Hi ADezii. Using A2003 I receive two error messages when I compile the code in the sample DB in post # 5. The compile errors both relate to the use of WindowState in class FormInfo.

The first error message relates to sub RetrieveCoords - method or data member not found.

.State = Val(GetSetting(AppName, _
strName, adhcState, Me.WindowState))

I wonder if the use of Me is incorrect here as WindowState is not a property of an Access form. There is a WindowState property of the form class available in .Net, however - as this MSDN link shows.

The second is in SaveCoords - expected variable or procedure, not enumerated type.

Call SaveSetting( _
AppName, strName, adhcState, WindowState)

Confusingly, there is a WindowState defined as an enumerated type in the class module (hence the error). Given the potential confusion over the .Net form class WindowState property I wonder if this was deliberate overloading on the part of the class designer?

-Stewart
Feb 17 '09 #13

FishVal
Expert 2.5K+
P: 2,653
@ADezii
Hello, ADezii.

Unfortunately module of FormInfo class doesn't contain "Get" part of WindowState property. Seems like the file you've attached is not the final working version. ;)

Regards,
Fish.
Feb 17 '09 #14

FishVal
Expert 2.5K+
P: 2,653
@CD Tom

Actually, both SaveCoords() and RetrieveCoords() methods could be thrown away if you don't intend to store form coordinates in windows registry.
Feb 17 '09 #15

100+
P: 443
That does take care of the Compile error and I don't intend to store form coordinates in the registry.
Thanks everybody for your help.
Feb 17 '09 #16

ADezii
Expert 5K+
P: 8,623
@ FishVal and Stewart, thanks guys for all your help, it is always appreciated. I've run this code on three different Access Versions, on three different PCs, and have had no problem. I'm more confused than ever. BTW, the base code was taken from the Access 2002 Desktop Developers Handbook, not exactly a 'shabby' source.

Back again and discovered my mistake. The DB that I Attached was only a subset of the actual Database which contained much more functionality in addition to the Center Form code. Obviously, in trying to make things more simple and compact, I've actually complicated everything and left a few things out in the process. Sorry for the run-around guys!
Feb 18 '09 #17

100+
P: 443
ADezii,
Can you send me the complete database I would like to see exactly what was causing the Compile error. I've removed the two sections and it seems to be working fine. Thanks for your help and also FishVal and Stewart.
Feb 18 '09 #18

ADezii
Expert 5K+
P: 8,623
@CD Tom
I will be more than happy to, but its size is beyond the limitation allowed for an Attachment. Simply send me your E-Mail Address in a Private Message (PM), and I'll send it to you that way. BTW, it is full of very interesting and functional code.
Feb 18 '09 #19

100+
P: 443
I've never sent a private message, have been looking around and don't see how it's done, sometime I really feel stupid.
Feb 18 '09 #20

Post your reply

Sign in to post your reply or Sign up for a free account.