Control Variable Referring to Tab Control

mohammadagul

PrinceAtif
Local time
Today, 21:02
Joined
Mar 14, 2004
Messages
298
Hello fiends .. i am using the following code for the on move mouse property of all my command buttons. i call this code from the on load event of my form and it works fine with all comand buttons ,, but if i try to make is work with Tab control or Toggle Buttons it give me an error message of "Variale not defined"


Code:
Option Compare Database
Option Explicit

Function gSetupCmdHighlights(frm As Form)
Dim cntl As Control, Sctn As Section, I As Integer

'Set the OnMouseMove event for all Command Buttons to function gMouseMove
'Set the OnMouseMove events for all non-Command button controls to function gClearCmdHighlights
For Each cntl In frm.Controls
  Select Case cntl.ControlType
    Case acCommandButton
      cntl.OnMouseMove = "=gMouseMove(""" & frm.NAME & """," & cntl.NAME & ")"

    Case 112 'Subform has different syntax (".Form.") shown below _
      cntl.Form.OnMouseMove = "=gClearCmdHighlights(""" & frm.Name & """)"

    Case Else
       On Error Resume Next
       cntl.OnMouseMove = "=gClearCmdHighlights(""" & frm.NAME & """)"
       On Error GoTo 0
  End Select
  Next

'If the mouse moves over a different report section, switch any highlight off
  On Error Resume Next
  For I = 0 To 4
    frm.Section(I).OnMouseMove = "=gClearCmdHighlights(""" & frm.NAME & """)"
  Next

  On Error GoTo 0
End Function

Function gMouseMove(frm, CtlName As Control)

'You only get here from OnMouseMove events that happen over command buttons
'If the command button is not already highlighted (in blue),
'the current fore color is saved in the tag property of the button
'and the colour is set to blue
'Then any other command buttons on the form are checked and if they
' are highlighted they are switched off.
'The second for each caters for the situation where you have two immediately adjacent command buttons with no 'intervening other form controls which would otherwise take care of switching off the highlighting
'on the command button being vacated.
'On the line marked *** you can experiment with different colours

Dim cntl As Control, fm As Form
Set fm = Forms(frm)
On Error Resume Next
If CtlName.ControlType = acCommandButton And CtlName.Tag = "" Then
  CtlName.Tag = CtlName.ForeColor 'Save original forecolor
  CtlName.ForeColor = 16711680 '***
End If

For Each cntl In fm.Controls
  If cntl.ControlType = acCommandButton And _
   CtlName.NAME <> cntl.NAME And cntl.Tag <> "" Then
    
    cntl.ForeColor = cntl.Tag
    cntl.Tag = ""
  End If
Next

On Error GoTo 0
Set fm = Nothing
End Function

Function gClearCmdHighlights(frm)

'Error-handler inserted on 18/09/04 at 12:14 by
'

On Error GoTo gClearCmdHighlights_Error



'This clears the highlights on all command buttons in the form
'and restores the original forecolors that were saved in the Tag properties

Dim cntl As Control, fm As Form
Set fm = Forms(frm)
For Each cntl In fm.Controls
  If cntl.ControlType = acCommandButton And cntl.Tag <> "" Then
    cntl.ForeColor = cntl.Tag
    cntl.Tag = ""
  End If
Next
Set fm = Nothing



gClearCmdHighlights_Exit:
Exit Function

gClearCmdHighlights_Error:
MsgBox "Unexpected error - " & err.Number & vbCrLf & vbCrLf & Error$, vbExclamation, "Accounting&&Invoicing - GCleCmdHig"
Resume gClearCmdHighlights_Exit

End Function
 
Last edited by a moderator:

Users who are viewing this thread

Back
Top Bottom