I found a block of code online (allenbrowne.com/highlight.html) that highlights form fields. Upon opening my form, I get a message box with Error 3265. The error occurs on the red line below. What can I do to fix this? I am using Access 2010.
Code:
Public Function SetupRequiredFields(frm As Form)
On Error GoTo Err_Handler
'Purpose: Set properties for all text boxes, combos, and list boxes, _
to highlight those bound to a required field.
'Argument: A reference to the form to setup.
'Usage: Set any form's On Load property to: =SetupRequired([Form])
'Return: True on success
Dim rs As DAO.Recordset 'Recordset of the form.
Dim ctl As Access.Control 'Each control on the form.
Dim strField As String 'Name of the field a control is bound to.
Set rs = frm.Recordset
For Each ctl In frm.Controls
Select Case ctl.ControlType
Case acTextBox, acComboBox, acListBox
'Ignore unbound, or bound to an expression.
strField = ctl.ControlSource
If (strField <> vbNullString) And Not (strField Like "=*") Then
[COLOR="Red"] With rs(strField)[/COLOR]
If (.Required) Or (.ValidationRule Like "*Is Not Null*") Then
ctl.BackColor = mlngcRequiredBackColor
Call MarkAttachedLabel(ctl)
End If
End With
End If
End Select
Next
SetupRequiredFields = True
Exit_Handler:
Set ctl = Nothing
Set rs = Nothing
Exit Function
Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "SetupRequiredFields()"
Resume Exit_Handler
End Function