How I can close pop up form when click somewhere else

masoud_sedighy

Registered User.
Local time
Today, 11:18
Joined
Dec 10, 2011
Messages
132
In the main form I have a list box, when I right click on each item on list box another form "frmshortcut" (pop up) will be open in the position of mouse that shows a list box for selecting items according to below code, now I would like when select another place (except "frmshortcut"), this form automatically will be close, like what we have in shortcut list of windows.​
Now when right click it is opened in the location of mouse click, but problem is, it is not closed automatically when click in other places of main form.​
Option Explicit​
[FONT=&quot][/FONT]​
Private Type POINTAPI​
x As Long​
y As Long​
End Type​
[FONT=&quot][/FONT]​
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long​
Private mp As [*clsMousePosition]​
[FONT=&quot] [/FONT]​
Private Sub ItemList_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)​
Const RIGHTBUTTON = 2​
Dim udtPos As POINTAPI​
Dim frm As Access.Form​
[FONT=&quot][/FONT]​
If Button = RIGHTBUTTON Then​
[FONT=&quot][/FONT]​
Set mp = New [*clsMousePosition]​
GetCursorPos udtPos​
[FONT=&quot][/FONT]​
[FONT=&quot][/FONT]​
DoCmd.OpenForm "frmshortcut"​
DoCmd.MoveSize udtPos.x * mp.TwipsPerPixelX, udtPos.y * mp.TwipsPerPixelY​
[FONT=&quot][/FONT]​
[FONT=&quot][/FONT]​
End If​
[FONT=&quot][/FONT]​
End Sub​
 
You could try adding an On Timer event for your popup form to check for focus (set it to 100 so it acts fast)
Code:
Private Sub Form_Timer()
If Screen.ActiveForm.Name <> "frmshortcut" Then DoCmd.Close acForm, "frmshortcut"
End Sub
 

Users who are viewing this thread

Back
Top Bottom