Results 1 to 9 of 9
  1. #1
    DarthBrute is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Location
    Phoenix, AZ
    Posts
    8

    Dynamically Centering Form Fields

    Ok I am extremely new to Access. I am currently modifying a form for a user to fill out. I have tried different "anchoring" and I have even tried a couple of VBA codes that honestly didn't make sense to me. Mainly because I don't understand VBA.

    I am really ready to just set my computer on fire.

    I don't understand why it is so difficult to keep form fields centered on the form when it is opened up. If the window is fullscreen/maximized I just want the form fields to be centered. Attached is a screen shot of Design View. Which is what I would like to have the form look like no matter the window size.

    I have tried different anchoring.
    Sometimes the columns switch places (i.e. first name and last name fields are on the opposite side in which they are displayed in design view.)


    Sometimes the left side is at the absolute left side of the window and the right side is at the absolute right side of the window.
    Or they are both on the right or both on the left.

    The just text boxes are easy, I just set to anchor to both left and right and center the field. But the form controls with labels just won't stay put.

    I have been trying to fix it for 5 or 6 days and I am at the end of my rope. Please help.


    Click image for larger version. 

Name:	access-form.PNG 
Views:	31 
Size:	31.2 KB 
ID:	39017

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,407
    It would help if you'd have shown the corresponding 'bad' form view.
    Is your db set for tabbed or overlapping windows?

  3. #3
    DarthBrute is offline Novice
    Windows 10 Access 2016
    Join Date
    Jul 2019
    Location
    Phoenix, AZ
    Posts
    8
    Quote Originally Posted by davegri View Post
    It would help if you'd have shown the corresponding 'bad' form view.
    Is your db set for tabbed or overlapping windows?
    Its set for tabbed. I have also tried the overlapping. But that doesn't affect the form when it is opened.Click image for larger version. 

Name:	access-form2.jpg 
Views:	32 
Size:	46.2 KB 
ID:	39018

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    maybe post a copy of your db as there seems to be something going on behind the scenes - like maybe your code.
    Why is it that you can't just position things in design view and leave it at that? Note that some control sizes cannot be adjusted, like checkboxes and option buttons, but their positions can be.
    EDIT - for the top 2, it looks like one is anchored left and the other, right. Maybe anchoring is your issue when all controls are considered?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    unless you want to spread all your controls out as well, why not just have a blank 'master' form with the same colour background and put this form on as a subform - then easy to centre the subform -

    in the master form resize event put

    mysubformname.left=(insidewidth-mysubformname.width)/2

    change mysubformname to whatever you have called your subform control

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    OP PM'd me and I downloaded db from onedrive. I will answer but not post the db changes without permission as I have no idea if there is anything proprietary in it and haven't looked. You will have to let me know if OK to post changes if you need the modified db.

    Let me start by saying that your issue will either be hard to control if using tabbed forms (which you are/were) and if different users have different screen sizes/resolutions. This requires what I would consider complex coding for novices, so if not necessary, a novice is perhaps best advised to avoid this. If you are the single user, or all users have the same view, then going to overlapping forms is better. That leaves 1 of 2 choices:

    - think like Alfred E. Neuman (What, me worry?) and forget about centering from screen to screen and let all fall as it may from left to right,
    - or apply the concepts below (those that apply to form design). AS NOTED - your primary problem is that of anchoring if you are trying to control space between left and right "columns" of controls. Should you have a middle column in any row (you do) then you are beat as there is no such thing as center anchoring. Also, plunking half on the left and the other half against the right is not what I'd call centering.

    Here's what I did to get going on Lead Form:
    - took off modal and reinstated shorcut menu property- is a PITA when trouble shooting.
    - removed layout from all controls, resized controls to fit my screen
    - dis-associated verify label from button
    - submit button is pointless and so is a subform for purpose of saving/submitting data- use OK or Cancel buttons (should be Save/Close and Cancel). I removed subform to gain space. I couldn't see the whole detail section on my screen, even with ribbon collapsed. Did not test your buttons after that.
    - changed to overlapping windows

    Here's how to make a form size 'static' without vba (can use vba MoveSize method on overlapping form but not tabbed AFAIK):
    Autocenter yes; border sizable; auto resize no;
    go to form view, drag to resize, save
    go to design view, border thin; min/max none;
    go to form view, save
    Now user cannot minimize or drag to resize. You may want to remove right click again so that it cannot be put into design view either.

    Other notes:

    Research Option Explicit - should be turned on FOREVER in every code project
    your db will not compile - many issues with API functions
    strDEC not declared - dangerous and code would never compile with OPTION EXPLICIT set
    there is no control named DateOfBirth.
    Age should never be stored, only calculated against DOB and current date. This could affect 2 procedures that use it
    your option buttons should be inside of an option frame (research that?)

    the form now looks the same each time it is opened...
    Click image for larger version. 

Name:	navyForm.jpg 
Views:	32 
Size:	122.0 KB 
ID:	39020

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Micron has done an excellent job of 'taming' your form and you may well be happy with the result he created.
    I totally agree that using tabbed document display and anchoring for controls can be a nightmare.
    Personally I always use overlapping windows and avoid the use of anchoring.

    However, managing different screen sizes and resolutions by means of automatic form resizing need not be at all difficult to apply.
    I wrote an extended tutorial on how to do this together with all the code you need.
    For details, see http://www.mendipdatasystems.co.uk/a...g-1/4594554784

    Although the supplied resizing module code is complex, using it is very easy.
    Just add the line 'ResizeForm Me' in the load event of the form to be resized
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,791
    Thanks for the contribution, Colin. I had your code in mind when I posted but having never used it (I may some day) didn't know how easy it may be to use. As you can see, my post was quite long as is, and it was getting a bit late to go looking for the links.

    I have since discovered that there is a nav form at play here, which may relegate all the effort to the trash pile. The subform control has to be wide enough for the widest form, thus anything smaller will be oriented left and there goes the centering that you set up in the single form view. A custom switchboard (not the built in one) would be the way to go, and opening all forms as overlapping and not tabs.

    DarthBrute: you might want to open a db, go to properties, and remove your personal info when uploading a db anywhere. I did this for you in this posted version just in case you'd care about it.

    Here is the modified db.

    eLeads Master_1.6 64BIT UPDATE.accdb.zip
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,974
    Hi Micron

    I also avoid navigation forms as coding them can be a pain

    I've been using automatic form resizing in all my production databases for almost 15 years. Its also included in many of my example apps.
    As I said in my previous reply, its very easy to use ...particularly if you follow the guidelines in my article.
    Much better to apply it when designing new databases rather than trying to adapt a long established application.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Centering text on a form?
    By ceb39usa in forum Reports
    Replies: 4
    Last Post: 09-17-2018, 08:35 AM
  2. Replies: 6
    Last Post: 05-01-2018, 04:20 PM
  3. Replies: 1
    Last Post: 11-11-2016, 08:22 AM
  4. Centering a Form within the Monitor screen
    By ashim in forum Programming
    Replies: 2
    Last Post: 04-13-2014, 02:20 PM
  5. Replies: 2
    Last Post: 06-01-2011, 09:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums