Solved

Loop through form controls and remove validation rule

Posted on 2010-08-26
2
467 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

867 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

21 Experts available now in Live!

Get 1:1 Help Now