473,394 Members | 1,843 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,394 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 25617
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.