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 apiGetWindowRec t Lib "user32" Alias _
"GetWindowR ect" (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 apiGetDeviceCap s Lib "gdi32" Alias "GetDeviceC aps"
(ByVal _
hdc As Long, ByVal nIndex As Long) As Long
Declare Function apiGetActiveWin dow Lib "user32" Alias _
"GetActiveWindo w" () As Long
Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal _
hwnd As Long) As Long
Declare Function apiGetClassName Lib "user32" Alias "GetClassNa meA" _
(ByVal hwnd As Long, ByVal lpClassname As String, ByVal _
nMaxCount As Long) As Long
Global Const TWIPSPERINCH = 1440
Sub ConvertPixelsTo Twisps(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 = apiGetDeviceCap s(hdc, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCap s(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(myFr m 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 ConvertPixelsTo Twisps(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
"Subclassin g & 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
'---------------