Button Location on form

unclefink

Registered User.
Local time
Today, 08:14
Joined
May 7, 2012
Messages
184
I have a form which has an exit button which I want located on the top right portion of the form header. When in design view on the form itself, the button is located where I want it; however when I look at the form in form view, I find the button is shifted to the left or in the center of the form.

I can extend the actual form in design view; however the size I build it to is not going to be the same for every different work station that may use this database.

Is there a way to make a button show up in a specific spot every time the specific form is open regardless of monitor size?
 
Yeah, you can change the buttons left & top properties when your form is loaded. Something like this maybe:

Let's say for some weird OCD related reason you wanted your button to be centered at 90% of the forms width, then your code should look something like this:

Code:
Me.MyCloseButton.Left = (Me.width * 0.9) - (me.myclosebutton.width / 2)

The brackets are not needed but it makes it look more readable
 
Thanks for the help. My ultimate intention is to have the button show up on the far right side of the form header. I do not want it centered.

I'll try the code you provided and change the numbers until it works out.

What information in the code would I need to change if any: ie: I presume "MyCloseButton" is the name of the button in your example.

Now looking around, where do I put this code?
 
I think you will find Me.Width will only return the current forms width NOT the window width. If you have a form that fits your screen (lets say 1280*1024 res) then the width would be c. 39cm. If you display this on a smaller res setting the form width will still be c. 39cm but obviously not everything is showing.

Use Me.WindowWidth instead (not sure what version of Access that showed up in but at least 2003). You would also have to check the value returned by the formula is not greater than the forms width or you may get some wierd display issues.

Put the code in the form_Open event
 
I'm afraid i'm not sure what you are talking about. I've got a sample db with the form in it which i'd like to post but I dont see an add option other than the link and image. Do you know how I can add this sample to a post?
 
Click Reply, then when the reply box is showing scroll down the page a little and you will see a long button "Manage Attachments". Just click on it and follow the prompts
 
Thank you much, there is always a first time for something and here is my first time.
 

Attachments

I checked the test.zip file G37Sam reposted and it appears to be exactly what I origionally posted. I did in fact check the left and top properties of the button and it comes up where I want it in design view but still comes up in the center on the form view. Should I make the design view larger and reset the button. I want the form to fill the page of any screen size when a user opens the database.
 
No G37Sam's test.zip is not waht was originally posted. It uses WindowWidth NOT form width (me.width). As a test of the difference, if you move the close label on test.zip over to the left and make the form narrower, then run it, the close label will still appear on the right hand side.

Is your form maximixed (in the OnOpen event put docmd.Maximize)?
Is it a pop up form?
 
Here is the code for the event procedures for "On Open".

Private Sub Form_Open(Cancel As Integer)
'Me.myclosebutton.Left = (Me.Width * 0.9) - (Me.myclosebutton.Width / 2)
Me.Command32.Left = Me.WindowWidth - Me.Command32.Width
End Sub

Is this whate you are speaking of?

When I open the form, it does expand and fill my screen; however the button is still showing int he center on top.

Pop up setting for the form says "no".
 
So i've been trying all sorts of things today with still no success. It appears as though the view is displaying at the form view size rather than the screen size. Any other suggestions?

Also I dont know a lot about VBA let alone how to use or place it, so if it requires such please bear with me.
 
This is strange. Is it possible for you to attach the form (either in the database or copy it to a new databse and attach that)? There must be a setting that is wrong.
Essentially what the code does is subtract the width of Command32 from the width of the window and use that figure as the left position for Command32. Try something for me, where you have this code now, put in the following and let us know the values;

msgbox me.width
msgbox me.windowwidth
exit sub
 
Here is a copy of the form. Also if you figure it out let me know what i'm doing wrong. I have several other forms that look similar to this one and have similar buttons doing the same thing. Hopefully whatever we do to fix this one will fix all of them.
 

Attachments

The values i wanted to see were:

msgbox me.width
msgbox me.windowwidth

but with the form in my hands i can sort that myself. I will get back to you as soon as possible after i get home and can get on a proper PC with Access 2010:banghead::banghead::banghead::banghead:
 
It works for me. However if you change anything on the screen (like open/close the shutter bar down the side) the position will not move until the form is reopened. check my version of test (oh and remove the msgbox code)
 

Attachments

Success. It seems to be working in 2010 and not 2007 version. Thats the part that sucks, i'm working at home on 07 and work on 10. Thank you very much for the help. I also applied the necessary changes to the other forms and it looks exactly as i want it.
 

Users who are viewing this thread

Back
Top Bottom