Solved

Loop through form controls and remove validation rule

Posted on 2010-08-26
2
466 Views
Last Modified: 2013-11-27
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.  
0
Comment
Question by:AaronGreene1906
  • 2
2 Comments
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 33535538
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

0
 
LVL 11

Accepted Solution

by:
LambertHeenan earned 500 total points
ID: 33535596
Oops. Wrong property. Try this...
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 = ""
                c.ValidationRule = ""
            ElseIf c.ValidationRule = strRuleText Then
                c.ValidationText = ""
                c.ValidationRule = ""
            End If
        End If
    Next c
    DoCmd.Close acForm, strForm, acSaveYes
End Sub

Open in new window

0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now