Search code examples
vbams-accessms-access-2010ms-access-2007

Disable Controls on Access Forms on Load


I am trying to create a form that allows me to control Access for people inputting data. The idea is to have all the controls disabled when the form loads and when they select different topics various fields would be selected accordingly. I know the long-hand way on how to do this field by field but I was hoping to do this as a batch but everything I try fails.

This is what I currently have

Dim control As control
Dim formName As String
Dim fieldName As String
Dim fieldParse As String


strFormName = "frm_Outfalls_Profile_Events"
For Each control In Forms(strFormName)
fieldName = control.Name
fieldParse = Left(fieldName, 5)
If fieldParse = "event" Then
    Me.fieldName.Enabled = False
End If
Next

Solution

  • A simplified version of your code which suspends errors to avoid cases where the Enabled property does not exist.

    On Error Resume Next
    For Each ctl In Forms.frm_Outfalls_Profile_Events.Controls
        ctl.Enabled = Not Left(ctl.Name, 5) = "event"
    Next ctl
    On Error GoTo 0