B. Meincke said:
Certainly...
Function MoveIt(strFormName As String, strControlName As _
String)
On Error GoTo Proc_Error
Dim iMoveX As Integer
Dim iMoveY As Integer
iMoveX = Int(1000 * Rnd()) - 500
iMoveY = Int(1000 * Rnd()) - 500
again:
Forms(strFormName).Controls(strControlName).Left = Forms
_(strFormName).Controls(strControlName).Left + iMoveX
Forms(strFormName).Controls(strControlName).Top = Forms
_(strFormName).Controls(strControlName).Top + iMoveY
Beep
Proc_Exit:
Exit Function
Proc_Error:
Select Case Err.Number
Case 2100
iMoveX = -iMoveX
iMoveY = -iMoveY
Resume again
Case Else
MsgBox "Error " & Err.Number
Resume Proc_Exit
End Select
End Function
LOL...
It's an April Fools joke, actually. I can't think of a sane reason for
wanting to do such a thing myself.
The above function will be called for each command button on our
switchboard's OnMouseMove event. All command buttons are on five tabs of a
tab control.
The error handler stops the code from failing when buttons hit the edges
of
the form, but I would like to restrict button movement to the tab control
area.
Hope this helps. Thanks for your continued assistance.
BJM
I had a quick play around with your code this morning, but was unable to
prevent the resizing of the tab control. Here's what I tried:
Function MoveIt(strFormName As String, strControlName As String)
'On Error GoTo Proc_Error
Dim iMoveX As Integer
Dim iMoveY As Integer
Dim newLeft As Integer, newTop As Integer
Dim Ctl As Access.Control
Set Ctl = Forms(strFormName).Controls(strControlName)
iMoveX = Int(1000 * Rnd()) - 500
iMoveY = Int(1000 * Rnd()) - 500
again:
newLeft = Ctl.Left + iMoveX
If (newLeft + Ctl.Width) > (TabCtl0.Left + TabCtl0.Width) Then
newLeft = (TabCtl0.Left + TabCtl0.Width) - Ctl.Width
End If
If newLeft < TabCtl0.Left Then newLeft = TabCtl0.Left
Ctl.Left = newLeft
newTop = Ctl.Top + iMoveY
If (newTop + Ctl.Height) > (TabCtl0.Top + TabCtl0.Height) Then
newTop = (TabCtl0.Top + TabCtl0.Height) - Ctl.Height
End If
If newTop < TabCtl0.Top Then newTop = TabCtl0.Top
Ctl.Top = newTop
Beep
'Proc_Exit:
' Exit Function
'Proc_Error:
' Select Case Err.Number
' Case 2100
' iMoveX = -iMoveX
' iMoveY = -iMoveY
' Resume again
' Case Else
' MsgBox "Error " & Err.Number
' Resume Proc_Exit
' End Select
End Function
Maybe you have more time than I do to polish it off, but that's the gist of
what I meant previously.
Good luck, and if you get this implemented I hope you manage to keep your
job ;-)