I have a form linked to a database that displays names and address of businesses. If the business has closed a text box 'txtDate_Closed' contains the date of closure. If the business is closed, I would like all text boxes on the form to have a yellow background. I do not want the background colour of labels to change so I need to be able to identify which controls on my form are textboxes. Here's my attempt (which doesn't work
Private Sub Status()
'If the business is closed, set the colour of the text boxes
'on the form to yellow otherwise set them to white
Dim MyCtrl As Control
Dim lngYellow As Long
Dim lngWhite As Long
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)
If AdoBrowse.Recordset!Date_Closed <> "" Then
For Each MyCtrl In Controls
Private Sub PracticeStatus()
'If the practice is closed, set the colour of the text boxes
'on the main form to yellow otherwise set them to white
Dim MyCtrl As Control
Dim lngYellow As Long
Dim lngWhite As Long
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)
If AdoBrowse.Recordset!Date_Closed <> "" Then
For Each MyCtrl In Controls
If TypeOf .Controls Is TextBox Then 'Problem here
MyCtrl.BackColor = lngYellow
End If
Next MyCtrl
Else
For Each MyCtrl In Controls
If TypeOf .Controls Is TextBox Then
MyCtrl.BackColor = lngWhite
End If
Next MyCtrl
End If
Any ideas??
Private Sub Status()
'If the business is closed, set the colour of the text boxes
'on the form to yellow otherwise set them to white
Dim MyCtrl As Control
Dim lngYellow As Long
Dim lngWhite As Long
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)
If AdoBrowse.Recordset!Date_Closed <> "" Then
For Each MyCtrl In Controls
Private Sub PracticeStatus()
'If the practice is closed, set the colour of the text boxes
'on the main form to yellow otherwise set them to white
Dim MyCtrl As Control
Dim lngYellow As Long
Dim lngWhite As Long
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)
If AdoBrowse.Recordset!Date_Closed <> "" Then
For Each MyCtrl In Controls
If TypeOf .Controls Is TextBox Then 'Problem here
MyCtrl.BackColor = lngYellow
End If
Next MyCtrl
Else
For Each MyCtrl In Controls
If TypeOf .Controls Is TextBox Then
MyCtrl.BackColor = lngWhite
End If
Next MyCtrl
End If
Any ideas??