Open pop up form at mouse cursor position (1 Viewer)

ChrisMore

Member
Local time
Today, 13:50
Joined
Jan 28, 2020
Messages
174
Hi all,

I have a list of products in a form which make up our inventory and when a product is clicked on I would like a pop up form to open just above the mouse cursor displaying the stock numbers for that product. I have this all set up and working except for the placement of the pop up form, currently it opens at the top of the screen which isn't ideal.

Any help would be much appreciated.

Thanks,
Chris
 

ChrisMore

Member
Local time
Today, 13:50
Joined
Jan 28, 2020
Messages
174
Alternatively, the pop up form could open above the active record in the products form, if that's possible...
 

isladogs

MVP / VIP
Local time
Today, 13:50
Joined
Jan 14, 2017
Messages
18,225
Have a look at the various forms in my example app
 

Mike Krailo

Well-known member
Local time
Today, 08:50
Joined
Mar 28, 2020
Messages
1,044
If you are just working within the canvas of the application, then:
Code:
DoCmd.MoveSize 0, 0  'Moves the form to upper left of canvas
The first argument is how much right you desire and the second is how much down you want. You will need to calculate the needed position based on your requirements.
 

ChrisMore

Member
Local time
Today, 13:50
Joined
Jan 28, 2020
Messages
174
If you are just working within the canvas of the application, then:
Code:
DoCmd.MoveSize 0, 0  'Moves the form to upper left of canvas
The first argument is how much right you desire and the second is how much down you want. You will need to calculate the needed position based on your requirements.
My products form has over 300 records so the user will be scrolling up and down the product list meaning the pop form would need to open at the location of the record depending on which has been selected. This is why I think it would work best to position the pop up form based on the mouse cursor.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:50
Joined
Sep 21, 2011
Messages
14,306
Cannot see why TBH :unsure:
As long as the form opens to the correct record, that would be all I need as a user.
Having a form jumping all over the place, would annoy me. :)
I would expect to see it in the same position each time.
 

ChrisMore

Member
Local time
Today, 13:50
Joined
Jan 28, 2020
Messages
174
Cannot see why TBH :unsure:
As long as the form opens to the correct record, that would be all I need as a user.
Having a form jumping all over the place, would annoy me. :)
I would expect to see it in the same position each time.
The pop up form is very narrow with an inside height of 567 twips and only opens when the product name field is clicked on so it won't jump all over the place. Having the form open above the cursor or active record each time effectively means it opens in the same place each time, just not the same position.

The reason I am having to go down this pop up route is because if the stock information (the data shown in the pop up form) is shown in the main form it runs very slow and laggy. Separating the stock information so it only appears on demand when a product is selected means the form will run fast and smooth.
 

ChrisMore

Member
Local time
Today, 13:50
Joined
Jan 28, 2020
Messages
174
Thank you for sharing this @isladogs, very informative. I like the look of your 'Zoom Box' with the following code:
Code:
Private Sub Text0_DblClick(Cancel As Integer)

'close zoom form if open
If CurrentProject.AllForms("frmZoom").IsLoaded = True Then DoCmd.Close acForm, "frmZoom"

strText = Nz(Me.Text0, "")
strCaption = "Text0 "

'check record containing text has been clicked
If Nz(Me.RecNum, "") <> "" And strText <> "" Then
intLeft = Me.WindowLeft + Me.Text0.Left + intRecSelWidth

'check if subform
If IsSubform Then
intBase = intTitleBarHeight + intHeightHeader + Me.WindowTop + Me.Text0.Top + Me.Text0.Height _
+ (Me.RecNum - 1) * Me.Detail.Height - intNavBarHeight - intBorderHeight
Else
intBase = intTitleBarHeight + intHeightHeader + Me.WindowTop + Me.Text0.Top + Me.Text0.Height _
+ (Me.RecNum - 1) * Me.Detail.Height
End If

'open / move the form
DoCmd.OpenForm "frmZoom"
Forms!frmZoom.Move intLeft, intBase
End If

End Sub

Please can I have more details on how this works because I might be able to adapt it to my project. I have managed to get it working but the zoom box doesn't align when the form is scrolled. The zoom box disappeared off screen when I clicked on a record after scrolling.
 

isladogs

MVP / VIP
Local time
Today, 13:50
Joined
Jan 14, 2017
Messages
18,225
Not sure why you posted the same response twice - please delete one of them

The article explains each of the forms in detail
I think the code is from Form2. RecNum is a hidden control used to determine the position below which the zoom box form frmZoom gets placed

1699979939337.png
 

ChrisMore

Member
Local time
Today, 13:50
Joined
Jan 28, 2020
Messages
174
Not sure why you posted the same response twice - please delete one of them

The article explains each of the forms in detail
I think the code is from Form2. RecNum is a hidden control used to determine the position below which the zoom box form frmZoom gets placed

View attachment 110953
Yes sorry about that, I did delete the first post. I replaced my post because I answered my own question. I have run into a problem with your code when scrolling down the form and selecting a record. The zoom box doesn't align when the form is scrolled and gradually disappears off screen as I work my way down the records in the form.
 

isladogs

MVP / VIP
Local time
Today, 13:50
Joined
Jan 14, 2017
Messages
18,225
Unfortunately, the approach used will not work correctly if the form is scrolled vertically.
 

MarkK

bit cruncher
Local time
Today, 05:50
Joined
Mar 17, 2004
Messages
8,181
You can also use a popup menu, if that would serve your purpose, as demonstrated here. A popup always displays at the current mouse pointer.
 

ChrisMore

Member
Local time
Today, 13:50
Joined
Jan 28, 2020
Messages
174
Unfortunately, the approach used will not work correctly if the form is scrolled vertically.
That's a shame. This would be almost perfect if it worked with a vertical scroll.

You can also use a popup menu, if that would serve your purpose, as demonstrated here. A popup always displays at the current mouse pointer.
Thanks for the suggestion, @MarkK. I am however struggling to see how this would fit with my project. This could be because of my lack of understanding of the code and how to adjust it to fit my purpose.
 

ChrisMore

Member
Local time
Today, 13:50
Joined
Jan 28, 2020
Messages
174
Please can we revert our thinking back to the title of this thread. Is it possible to open a pop up form at the cursor position? I have found similar posts on other forums, such as https://www.accessforums.net/showthread.php?t=23837 but haven't been able to get the code working on my project. Does anyone have any thoughts on opening a form at the cursor position?
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:50
Joined
Sep 21, 2011
Messages
14,306
Please can we revert our thinking back to the title of this thread. Is it possible to open a pop up form at the cursor position? I have found similar posts on other forums, such as https://www.accessforums.net/showthread.php?t=23837 but haven't been able to get the code working on my project. Does anyone have any thoughts on opening a form at the cursor position?
What part are you struggling with?, as it seems pretty self explanatory?
I would start with the first solution and then perhaps entertain the second solution with extra variables/objects.
 

MsAccessNL

Member
Local time
Today, 14:50
Joined
Aug 27, 2022
Messages
184
I have used the absolute postion times the the detailheigth (in designform) to set the Form.Top of the popup form (if the Mainform is a continuous form). But i don't think it will work correct with scrolling. You could put the continuous form on a Mainform and stretch the anchor of the subformcontrol down to bottom or You could use the absolute position also to set the height of the subformcontrol, so you don't have to scroll (if there is enough space left).
 

sonic8

AWF VIP
Local time
Today, 14:50
Joined
Oct 27, 2015
Messages
998
Is it possible to open a pop up form at the cursor position? I have found similar posts on other forums, such as https://www.accessforums.net/showthread.php?t=23837 but haven't been able to get the code working on my project.
It should definitely be possible to open a form at the cursor position.
The other thread you linked to looks very promising to me. Where/why did it fail to work for you?
 

ChrisMore

Member
Local time
Today, 13:50
Joined
Jan 28, 2020
Messages
174

Users who are viewing this thread

Top Bottom