Link to home
Start Free TrialLog in
Avatar of Aaron Greene
Aaron GreeneFlag for United States of America

asked on

Loop through form controls and remove validation rule

I would like ot know if/how I can write a procedure to loop through all the valid controls in a form (textboxes and comboboxes to remove a bogus validation rule.  
Avatar of Lambert Heenan
Lambert Heenan
Flag of United States of America image

This might do the trick...

Sub PurgeValidationRule(strForm As String, Optional strRuleText As String = "")
Dim boolRemoveAllValidation As Boolean
Dim c As Control

    boolRemoveAllValidation = strRuleText = ""
    DoCmd.OpenForm strForm, acDesign
    For Each c In Forms(strForm)
        If TypeOf c Is TextBox Or TypeOf c Is ComboBox Then
            If boolRemoveAllValidation Then
                c.ValidationText = Null
            ElseIf c.ValidationText = strRuleText Then
                c.ValidationText = Null
            End If
        End If
    Next c
    DoCmd.Close acForm, strForm, acSaveYes
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lambert Heenan
Lambert Heenan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial