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

Open a form to the position of the mouse

P: n/a
I have a command button on a continuous subform and I want the user to
click it to open a small popup form that opens in the position of the
mouse (which is the same as the position of the command button on each
record of the continuous subform.)
I'm hoping someone can tell me how to do this.
Thanks,
lq

Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Rog
DoCmd.OpenForm yourform
DoCmd.MoveSize a, b, c, d

where a=right, b=down, c=width, d=height in twips.

Not sure how you can determine where your mouse pointer is located
though.

Rog

Nov 13 '05 #2

P: n/a
Rog
Check out this thread:
http://groups-beta.google.com/group/...20b2dc3cccd4ef

Nov 13 '05 #3

P: n/a
Rog wrote:
DoCmd.OpenForm yourform
DoCmd.MoveSize a, b, c, d

where a=right, b=down, c=width, d=height in twips.

Not sure how you can determine where your mouse pointer is located
though.


Perhaps, thinking out loud, when the button to open the form is clicked you open the form
in hidden mode.

Once the user clicks the mouse, in the MouseDown or MouseUp code you would then move the
form with the DoCmd.MoveSize() call and then make the form visible. I'm not even sure if
you can move a hidden form with MoveSize().

I left out the hardest part - once the form is opened hidden you'll need to be able to
handle the mouse click wherever it occurs within the user's desktop. Since that could be
outside the Access window you'll need to be able to subclass or hook the system mouse
event. Not sure how that would be done but a great resource is the O'Reilly book
"Subclassing & Hooking With Visual Basic".

It should be evident that this isn't an easy task to accomplish (unless your last name is
Lebans). Of course someone may have a better idea...

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #4

P: n/a
I figured this out on my own so I'm posting a solution for anyone
having the same concerns:

Put the following in a code module:

Declare Sub GetCursorPos Lib "user32" (lpPoint As typPOINTAPI)

Type typPOINTAPI
x As Long
Y As Long
End Type

Declare Function apiGetWindowRect Lib "user32" Alias _
"GetWindowRect" (ByVal hwnd As Long, lpRect As RECT_Type) As Long
Declare Function apiGetDC Lib "user32" Alias "GetDC" _
(ByVal hwnd As Long) As Long
Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal _
hwnd As Long, ByVal hdc As Long) As Long
Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps"
(ByVal _
hdc As Long, ByVal nIndex As Long) As Long
Declare Function apiGetActiveWindow Lib "user32" Alias _
"GetActiveWindow" () As Long
Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal _
hwnd As Long) As Long
Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Long, ByVal lpClassname As String, ByVal _
nMaxCount As Long) As Long

Global Const TWIPSPERINCH = 1440

Sub ConvertPixelsToTwisps(l As Long, t As Long, x As Long, Y As Long)
On Error GoTo myErr

Dim hdc As Long, hwnd As Long, RetVal As Long, XPIXELSPERINCH,
YPIXELSPERINCH

Const LOGPIXELSX = 88
Const LOGPIXELSY = 90

'get the current number of pixels per inch, which is
resolution-dependent:
hdc = apiGetDC(0)
XPIXELSPERINCH = apiGetDeviceCaps(hdc, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCaps(hdc, LOGPIXELSY)
RetVal = apiReleaseDC(0, hdc)

'compute and return the measurements in twips:
If l > 0 Then l = (l / XPIXELSPERINCH) * TWIPSPERINCH '>left
If t > 0 Then t = (t / XPIXELSPERINCH) * TWIPSPERINCH '>top
x = (x / XPIXELSPERINCH) * TWIPSPERINCH '>width
Y = (Y / YPIXELSPERINCH) * TWIPSPERINCH '>height

myExit:
Exit Sub
myErr:
msgbox Err.Number & " " & Err.Description
Resume myExit
End Sub

In the module opening your form paste the following:

Function OpenMyForm(myFrm as String)
'myFrm is the name of your form to open to your current mouse pointer
location

Dim TipPoint As typPOINTAPI, myvar1 As Long, myvar2 As Long, myFrm As
String, myStatusFile As String
'get the current mouse position:
GetCursorPos TipPoint

myvar1 = (TipPoint.x)
myvar2 = (TipPoint.Y)

Call ConvertPixelsToTwisps(myvar1, myvar2, 0, 0)

DoCmd.OpenForm myFrm

'>position the form
DoCmd.MoveSize myvar1, myvar2

End Function

John Mishefske wrote:
Rog wrote:
DoCmd.OpenForm yourform
DoCmd.MoveSize a, b, c, d

where a=right, b=down, c=width, d=height in twips.

Not sure how you can determine where your mouse pointer is located
though.


Perhaps, thinking out loud, when the button to open the form is clicked you open the form
in hidden mode.

Once the user clicks the mouse, in the MouseDown or MouseUp code you would then move the
form with the DoCmd.MoveSize() call and then make the form visible. I'm not even sure if
you can move a hidden form with MoveSize().

I left out the hardest part - once the form is opened hidden you'll need to be able to
handle the mouse click wherever it occurs within the user's desktop. Since that could be
outside the Access window you'll need to be able to subclass or hook the system mouse
event. Not sure how that would be done but a great resource is the O'Reilly book
"Subclassing & Hooking With Visual Basic".

It should be evident that this isn't an easy task to accomplish (unless your last name is
Lebans). Of course someone may have a better idea...

--
'---------------
'John Mishefske
'---------------


Nov 13 '05 #5

P: n/a
Lauren have you tested your solution under the following scenarios?

The Main Access application Window sized smaller then if maximized.

The Main Access application Window sized smaller then if maximized and
not in the top left corner

Your form's Popup property for both Yes and No.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"lauren quantrell" <la*************@hotmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I figured this out on my own so I'm posting a solution for anyone
having the same concerns:

Put the following in a code module:

Declare Sub GetCursorPos Lib "user32" (lpPoint As typPOINTAPI)

Type typPOINTAPI
x As Long
Y As Long
End Type

Declare Function apiGetWindowRect Lib "user32" Alias _
"GetWindowRect" (ByVal hwnd As Long, lpRect As RECT_Type) As Long
Declare Function apiGetDC Lib "user32" Alias "GetDC" _
(ByVal hwnd As Long) As Long
Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal _
hwnd As Long, ByVal hdc As Long) As Long
Declare Function apiGetDeviceCaps Lib "gdi32" Alias "GetDeviceCaps"
(ByVal _
hdc As Long, ByVal nIndex As Long) As Long
Declare Function apiGetActiveWindow Lib "user32" Alias _
"GetActiveWindow" () As Long
Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal _
hwnd As Long) As Long
Declare Function apiGetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Long, ByVal lpClassname As String, ByVal _
nMaxCount As Long) As Long

Global Const TWIPSPERINCH = 1440

Sub ConvertPixelsToTwisps(l As Long, t As Long, x As Long, Y As Long)
On Error GoTo myErr

Dim hdc As Long, hwnd As Long, RetVal As Long, XPIXELSPERINCH,
YPIXELSPERINCH

Const LOGPIXELSX = 88
Const LOGPIXELSY = 90

'get the current number of pixels per inch, which is
resolution-dependent:
hdc = apiGetDC(0)
XPIXELSPERINCH = apiGetDeviceCaps(hdc, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCaps(hdc, LOGPIXELSY)
RetVal = apiReleaseDC(0, hdc)

'compute and return the measurements in twips:
If l > 0 Then l = (l / XPIXELSPERINCH) * TWIPSPERINCH '>left
If t > 0 Then t = (t / XPIXELSPERINCH) * TWIPSPERINCH '>top
x = (x / XPIXELSPERINCH) * TWIPSPERINCH '>width
Y = (Y / YPIXELSPERINCH) * TWIPSPERINCH '>height

myExit:
Exit Sub
myErr:
msgbox Err.Number & " " & Err.Description
Resume myExit
End Sub

In the module opening your form paste the following:

Function OpenMyForm(myFrm as String)
'myFrm is the name of your form to open to your current mouse pointer
location

Dim TipPoint As typPOINTAPI, myvar1 As Long, myvar2 As Long, myFrm As
String, myStatusFile As String
'get the current mouse position:
GetCursorPos TipPoint

myvar1 = (TipPoint.x)
myvar2 = (TipPoint.Y)

Call ConvertPixelsToTwisps(myvar1, myvar2, 0, 0)

DoCmd.OpenForm myFrm

'>position the form
DoCmd.MoveSize myvar1, myvar2

End Function

John Mishefske wrote:
Rog wrote:
DoCmd.OpenForm yourform
DoCmd.MoveSize a, b, c, d

where a=right, b=down, c=width, d=height in twips.

Not sure how you can determine where your mouse pointer is located
though.


Perhaps, thinking out loud, when the button to open the form is clicked you open the form in hidden mode.

Once the user clicks the mouse, in the MouseDown or MouseUp code you would then move the form with the DoCmd.MoveSize() call and then make the form visible. I'm not even sure if you can move a hidden form with MoveSize().

I left out the hardest part - once the form is opened hidden you'll need to be able to handle the mouse click wherever it occurs within the user's desktop. Since that could be outside the Access window you'll need to be able to subclass or hook the system mouse event. Not sure how that would be done but a great resource is the O'Reilly book "Subclassing & Hooking With Visual Basic".

It should be evident that this isn't an easy task to accomplish (unless your last name is Lebans). Of course someone may have a better idea...

--
'---------------
'John Mishefske
'---------------


Nov 13 '05 #6

P: n/a
Stephen,
I have tested this with the Access 2000 application window in various
states including maximized, smaller and larger than the form calling
the function. I have used and tested it on popup and non-popup forms
alike, however the form that opens using this method is always set as a
popup form, since I use it as a substitute for a shortcut menu.
lq

Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.