Results 1 to 7 of 7
  1. #1
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Setting Validation rule for about 20 controls (Access 2002/2003)

    I have about 20 controls where I want to set the Validation Rule and Validation Text for. These control start with HS or AP or II or CC.
    Can I do this via a loop?
    I'm sure it can be done but I could not find it in the Help on a dialup connection.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Setting Validation rule for about 20 controls (Access 2002/2003)

    If those are the only controls whose name starts with one of those conbinations, you can use something like this:

    Dim ctl As Control
    Dim strFirst2 As String
    For Each ctl In Me.Controls
    strFirst2 = Left(ctl.Name, 2)
    Select Case strFirst2
    Case "HS", "AP", "II", "CC"
    ctl.ValidationRule = ">0"
    ctl.ValidationText = "Only positive values allowed!"
    End Select
    Set ctl = Nothing
    End Sub

    Change the ValidationRule and ValidationText as needed. If you need to include the name of the control in the rule or text, concatenate with ctl.Name.

  3. #3
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Setting Validation rule for about 20 controls (Access 2002/2003)

    Thanks Hans, I was not sure how to address the loop of controls.

    The main instruction I required to know was:
    For Each ctl In Me.Controls

  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Setting Validation rule for about 20 controls (Access 2002/2003)

    A problem I have encountered is that some labels have the same prefixes.

    What I need to do is test if the control is a text box. I don't know how to do this. Anyone?

  5. #5
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Setting Validation rule for about 20 controls (Access 2002/2003)

    I have found what I was looking for in the Search facility.

    It was a control's ControlType testing to AcTextType.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Setting Validation rule for about 20 controls (Access 2002/2003)

    I presume you mean acTextBox instead of acTextType.

  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Setting Validation rule for about 20 controls (Access 2002/2003)

    Your presumption is correct, as always.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •