Question : On Open / Current Event Handler Question

The code in the On Open event handler of my form is expected to (Lock orUnlock / Enabled or Disable) based or defined login permissions.

At the same time when the form opens, the Call to CtlColor function kicks in at the On Current Event.

I know that the code in my On Open Event Code is trying to lock or unlock the controls while the On Current event is trying to set the propriate color at the same time my form opens.

In other words there is a conflict between the two code (The On Current and the On Open Event Code).

Below is the error I get when the form opens:

The error I am getting is a Run-Time Error'428'
Object doesn't support this property or method.

I need the two code to work, so how can I tweak or resolve the conflict.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
Private Sub Form_Open(Cancel As Integer)
On Error GoTo Form_Open_Error

' If CheckAccessID = False Then Cancel = True

	Call LockEm ' <---------------
 
    DoCmd.Maximize

End Sub

' ******************
Private Sub LockEm()
Dim ctr As Control
    For Each ctr In Me.Controls
       Select Case ctr.ControlType
        Case acTextBox, acListBox, acComboBox
            If g_lAccessID = 6 And (left(ctr.Name, 3) = "txt" Or left(ctr.Name, 3) = "cbo" Or left(ctr.Name, 3) = "chk" Or left(ctr.Name, 3) = "l_") Then
                    ctr.Locked = True
            Else
                    ctr.Locked = False
            If g_lAccessID = 6 And left(ctr.Name, 3) = "btn" Then
                    ctr.Enabled = False
            Else
                    ctr.Enabled = True
                End If
             End If
            End Select
        Next ctr
End Sub

' ***********************************************************************************************
Private Sub Form_Current()
	Call CtlColors
End Sub

' *****************
Function CtlColors()
Dim dtrl As Control '<----------------
Select Case Me.cboGroup.Column(0)
    
    Case "STU" 
    
        For Each dtrl In Me.Controls
          
            If Me!cboCourseType.Column(0) = "NC" Then

                If HasTag(dtrl.tag, "YW") Then
                    dtrl.BackColor = 8454143 '<--Yellow             '<------- Error line
                    dtrl.ForeColor = -2147483640 ' Bold Black Font 
                End If
                
            ElseIf Me!cboCourseType.Column(0) = "LA" Then
                
                If HasTag(dtrl.tag, "YW") Then
                    dtrl.BackColor = 15243799 '<----Light Blue  
                    dtrl.ForeColor = 16777215 '<----White font
		End If
            End If
        Next dtrl
    End Select
Exit Function
End Function

Answer : On Open / Current Event Handler Question

Have you added a tag to a control that doesn't have a backcolor property, such as a checkbox?
(or alternatively is the HasTag function returning an incorrect True value)
Random Solutions  
 
programming4us programming4us