Question : format control based on passing form and control name

Rather than changing the background color in every Entry and Exit event for an ACCESS 2003 database form, I would like to create a function that does this so if I want to change the colors, I only have to do it in once place.  However, when I try to pass the form's name, either as a string for the form name, I get errors such as variable not declared or datatype mismatched.
1:
2:
3:
4:
5:
6:
Public Sub OnFocusColors(frmName As Form, ctlName As Control)
    Forms!frmName.cltName.BackColor = 16709086
 End Sub
Public Sub LostFocusColors(frmName As Form, ctlName As Control)
 Forms!frmName.cltName.BackColor = 16777215
End Sub

Answer : format control based on passing form and control name

I would use the Activate/Deactivate events. See the code. Notice I changed the parameters to strings.

Lee


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Public Sub OnFocusColors(frmName As String, ctlName As String)
    Forms(frmName).Controls(ctlName).BackColor = vbRed
End Sub
Public Sub LostFocusColors(frmName As String, ctlName As String)
    Forms(frmName).Controls(ctlName).BackColor = vbBlue
End Sub

Private Sub Form_GotFocus()
    Call OnFocusColors(Me.Name, Text0.Name)
End Sub

Private Sub Form_LostFocus()
    Call LostFocusColors(Me.Name, Text0.Name)
End Sub
Random Solutions  
 
programming4us programming4us