Encounter error when setting properties value for a field in a loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BL3WC
    New Member
    • Nov 2008
    • 3

    Encounter error when setting properties value for a field in a loop

    Hi,

    I encountered an error "Object not supporting this properties or method" while trying to set a checkbox value to 'True" in a loop. The VBA code I use is as follow:

    Set a value to intcount (say set intcount to 2)

    ME("FieldName" & intcount).Prope rties.Value = True

    increment intcount by 1 and loop back to set another checkbox value to True base on some conditions.

    If I use Me.FieldName2.V alue = True, this is accepted. But I need to use a loop to set the value base on some conditions as there are a lot of checkboxes to handle.

    Can somebody points out what is wrong with the above codes?

    Thanks very much for your help.

    BL
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    Look at the two pieces of code:

    Doesn't work

    ME("FieldName" & intcount).Properties.Value = True

    Works

    Me.FieldName2.V alue = True

    What's really different?

    You've added an inappropriate Property to your first statement.

    ME("FieldName" & intcount).Properties.Value = True

    should be

    ME("FieldName" & intcount).Value = True

    without the "Properties ."

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • MikeTheBike
      Recognized Expert Contributor
      • Jun 2007
      • 640

      #3
      Originally posted by BL3WC
      Hi,

      I encountered an error "Object not supporting this properties or method" while trying to set a checkbox value to 'True" in a loop. The VBA code I use is as follow:

      Set a value to intcount (say set intcount to 2)

      ME("FieldName" & intcount).Prope rties.Value = True

      increment intcount by 1 and loop back to set another checkbox value to True base on some conditions.

      If I use Me.FieldName2.V alue = True, this is accepted. But I need to use a loop to set the value base on some conditions as there are a lot of checkboxes to handle.

      Can somebody points out what is wrong with the above codes?

      Thanks very much for your help.

      BL
      Hi

      On the basis that 'FieldName2' is the name of the field that is bound to a CheckBox control of the same name, then any of these will set it to yes/true

      [FieldName2] = True

      FieldName2.Valu e = True

      Me.Controls("Fi eldName2") = True

      Dim intcount As Integer
      intcount = 2

      Me.Controls("Fi eldName" & intcount) = True


      I think it is the last one you are looking for !?



      MTB

      Comment

      • BL3WC
        New Member
        • Nov 2008
        • 3

        #4
        Originally posted by MikeTheBike
        Hi

        On the basis that 'FieldName2' is the name of the field that is bound to a CheckBox control of the same name, then any of these will set it to yes/true

        [FieldName2] = True

        FieldName2.Valu e = True

        Me.Controls("Fi eldName2") = True

        Dim intcount As Integer
        intcount = 2

        Me.Controls("Fi eldName" & intcount) = True


        I think it is the last one you are looking for !?



        MTB
        Thanks Linq and MTB for your answer. I now have the correct setting in my application.

        I am quite new to the Access VBA syntax and got a bit consfued with the various syntax you suggested.

        1. Why do some codes use the following syntax:
        "FieldName.Prop erties("Value") = xxx" instead of directly use the syntax "FieldName.Valu e = xxx"?

        2. Are there situations that one should use the first one instead of the other?

        3. What are the valid situations to add ".Control" before the field name?

        Thanks again for your reply.
        BL

        Comment

        Working...