Solved

Loop through form controls and remove validation rule

Posted on 2010-08-26
2
471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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