Link to home
Start Free TrialLog in
Avatar of martmac
martmacFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Moving a borderless window using VBA in Ms Access 2010

Does anyone know of a way to move a borderless window using VBA in MS Access?
Avatar of martmac
martmac
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Sorry should have added, being able to drag it to a new position
Avatar of IrogSinta
Borderless or not, you can use the MoveSize method which affects the form that has the focus:
DoCmd.MoveSize Right, Down, Width, Height

In your case, you would need to use the first 2 parameters to move a certain number of Twips from the upper left corner of the Database window.  For instance: DoCmd.MoveSize 1440, 2880 will move the form 1 inch from the left and 2 inches down since there are 1440 Twips in an inch.
Avatar of martmac

ASKER

Thanks for your feedback, much appreciated. On reflection, my question was poorly worded. What I want to do is be able to drag it to a new location and it stay there on MouseUp. I appreciate that this is what dialogue style forms are for, but I am looking for a more contemporary feel which you get with borderless forms, but the inability to drag and reposition is a bit of a drawback.
the closest you can get to a borderless form that you can reposition by dragging with the mouse is to set the following

Border style  Dialog
Navigation Button No
Record selector No
Close Button No
Control Box No
MinMax Button No
Moveable Yes

and set the Caption property to a space, so no caption will show.
ASKER CERTIFIED SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
First give what Ron posted a try, then report back to him

<being able to drag it to a new position >
The short answer is, No

<I am looking for a more contemporary feel which you get with borderless forms,>
This "Feel" is not something that is built into MS Access.

In Access, the only way to manually move a form is to grab onto the titlebar.
With a borderless form, you have no real Titlebar.

So in the most basic sense what you are asking for is not possible.

There might be another way to do this on the MouseMove event of the detail section, but AFAICT, it would need to involve monitoring the cursor position, then multiplying by some "factor" to account for the users screen resolution... But this would be incredibly resource intensive, as each incremental change in the mouse position would trigger this code to run, and "redraw" the form on the screen...

<<being able to drag it to a new position >>
In other words, without a titlebar, there is no other built in way in Access to manually drag a form to a new position.

You can closely simulate a borderless form by:
Setting the Backcolor to roughly the same color as the title bar, then set the following form properties:
User generated image
...Then you end up with something like this, that you can move without needing any code...:
User generated image
JeffCoachman
Regarding my earlier post, I also just tried using the code in the each section's MouseDown event; that is, the Header, Detail, and Footer section.  Doing it this way allows you to drag the form no matter what part of the form you click (as long as it isn't on another control).  

Interestingly, if you put the code in the Form's MouseDown event, the only  way to move the form is by the Record Selector.  Rather useless for me since I always keep the Record Selector hidden.  

Personally, I like the idea of putting the code on an icon that looks like it symbolizes movement.  I might just use this on a couple of borderless forms I have at work.

:-)
Ron
Avatar of martmac

ASKER

Fantastic, just the ticket, that has done the trick. Thanks so much.

I actually put a white panel behind all the form elements and attached the MouseDown code to that, now you can drag whenever you select any part of the form outside of the area covered by a control. Works very well indeed as I have the cursor set to change to a hand over the active area.

Thanks again
"With a borderless form, you have no real Titlebar."

Of course,  you can create your own title bar in the Form Header - even with a Red X to Close.