473,289 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Open a form to the position of the mouse

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
6 25584
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
Rog
Check out this thread:
http://groups-beta.google.com/group/...20b2dc3cccd4ef

Nov 13 '05 #3
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
1
by: lauren quantrell | last post by:
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...
8
by: NeoAsimov | last post by:
Hello, There is what I want to do. I worked on the problem since 6 hours but I had a problem (probably stupid) and I dont know how to resolve it. I need to have an Mouse Event Click when...
3
by: Robert Lochon | last post by:
Hi ! I've got this strange problem : When I press the left-button and move my mouse, my form moves just as intended. But if I make big movements, the cursor shifts slightly. And it ends with...
0
by: Raj Chudasama | last post by:
In dot net 2003 on Xp when you go to the file menu and select Open file a dialog box opens up on the left hand side there are items such as history My Projects Desktop Favorites My Network...
18
by: Colin McGuire | last post by:
Hi - this was posted last weekend and unfortunately not resolved. The solutions that were posted almost worked but after another 5 days of working on the code everynight, I am not further ahead....
5
by: sagar | last post by:
is there any way to find the position of mouse click on a form actually the problem is i m having more than one controls on a form i want to find which control is selected using mouse down any...
1
by: Marcolino | last post by:
Hi, I'm new with VB.net and I comming from VB6 programming. I need to open a little form in Modal and child of MDI, with the top- left corner where the mouse has clicked. I tryed this code but...
3
by: Boki | last post by:
Hi All, I saw the paint.net program, when mouse hover, the color palette become 100% opacity. I try the code below, the issue is I also have some other controls ( textbox/button ) in my form,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.