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?
martmacAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

martmacAuthor Commented:
Sorry should have added, being able to drag it to a new position
0
IrogSintaCommented:
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.
0
martmacAuthor Commented:
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.
0
The Five Tenets of the Most Secure Backup

Data loss can hit a business in any number of ways. In reality, companies should expect to lose data at some point. The challenge is having a plan to recover from such an event.

Rey Obrero (Capricorn1)Commented:
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.
0
IrogSintaCommented:
The following code is a modification of that posted by John Conwell on this link.  Since his code is meant to move controls, I tweaked it to move the form instead.  This code is meant to be placed inside the form module; however, if you have more than one borderless forms, it would be better to stick this in a Public module.  If you go with the latter route, you would need the change the Private keywords to Public.  You would also need to add the Public keyword right before each Const declaration.

First off, put the following code at the top of a module:
Const WM_NCLBUTTONDOWN = &HA1
Const HT_CAPTION = 2
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Open in new window

Then in your form, insert an image icon that users would be able to recognize as "form movement" or maybe a label that just says "Drag Me."  In that control's MouseDown event, add the following code:
    ReleaseCapture
    SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HT_CAPTION, 0

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
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:
properties
...Then you end up with something like this, that you can move without needing any code...:
Form
JeffCoachman
0
Rey Obrero (Capricorn1)Commented:
:-0
0
IrogSintaCommented:
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
0
martmacAuthor Commented:
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
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
"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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.