Here is what I have so far:
I have something which works, But I know that is not a clean way to do that. Anyway, I also added a hidden frame to my main form which will be visible on mouse move.
Here is my code:
This Click event on a class module will show the second userform of CurrentJob
Private Sub Label1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
Dim m, n&
If Button = XlMouseButton.xlPrimaryButton And MainMap.Edit.Caption = "Done" Then
Label1.Left = Label1.Left + X - x_offset
Label1.Top = Label1.Top + Y - y_offset
ElseIf MainMap.Edit.Caption = "Go to Edit Mode" Then
With MainMap.Frame1
.Visible = True
.WorkerN = Label1.Caption
.LBcurr = openJobs
.LClsd = WorksheetFunction.CountIfs(oprecord.Range("e:e"), Label1.Caption, oprecord.Range("f:f"), Date, oprecord.Range("s:s"), "CLOSED")
End With
'if wanted to use the separeate form
If MainMap.TglB1 And Not CurrentJob.Visible Then
With CurrentJob
.Caption = "Current Job of " & Label1.Caption
.LCurr = openJobs
.LLast = LastJob
.LClsd = WorksheetFunction.CountIfs(oprecord.Range("e:e"), Label1.Caption, oprecord.Range("f:f"), Date, oprecord.Range("s:s"), "CLOSED")
n = Right(Label1.Tag, Len(Label1.Tag) - 1)
.LAc = IIf(n > 288, "N/A", Fix((n - 1) / 24) + 70006)
m = WorksheetFunction.VLookup(Label1.Caption, rooster.Range("b:e"), 4, 0)
.LSkill = Right(m, Len(m) - InStr(1, m, " "))
.StartUpPosition = 0
.Top = IIf(Label1.Top > MainMap.Height / 2, Label1.Top - .Height, Label1.Top + Label1.Height)
.Left = IIf(Label1.Left > MainMap.Width / 2, Label1.Left - .Width, Label1.Left + Label1.Width)
.Show
End With
End If
' separate form code ends here
End If
End Sub
Also on the second form:
Private Sub UserForm_Activate()
ontime = True
Application.ontime Now + TimeValue("00:00:02"), "closeee", Now + TimeValue("00:00:07")
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'On Error Resume Next
ontime = False
x1 = X
y1 = Y
mouseleft Me
End Sub
and also in another module
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Type POINTAPI
X As Long
Y As Long
End Type
Sub closeee()
If ontime And CurrentJob.Visible Then
CurrentJob.Hide
ontime = False
End If
End Sub
Sub mouseleft(Optional ByRef frm As Object)
Dim CurPos As POINTAPI, h1&, w1&
GetCursorPos CurPos
If frm Is Nothing Then
h1 = 0
w1 = 0
Else
With frm
h1 = .Height
w1 = .Width
End With
End If
Do While CurPos.X <= x1 + h1 And CurPos.Y <= y1 + w1 And CurPos.X > x1 And CurPos.Y > y1
frm.Visible = True
DoEvents
Loop
If frm.Visible Then frm.Hide
End Sub
I also used one of the class codes to detect when mouse left these labels in my main form.
Anyway, I think if I can do it by that wait triggered method, that would be better. I didn't work on that, as I am developing other parts of my app now.
Thanks a lot.
M