Try this: Needs 2 CommandButtons
Code:
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim W_RECT As RECT
Private Sub Command1_Click()
'Trap the cursor
GetWindowRect Me.hwnd, W_RECT
ClipCursor W_RECT
End Sub
Private Sub Command2_Click()
'Untrap the cursor
GetWindowRect GetDesktopWindow, W_RECT
ClipCursor W_RECT
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call Command2_Click
End Sub