Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Nov 2008
Posts: 2
#1: Nov 21 '08
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).Properties.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.Value = 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's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,002
#2: Nov 21 '08

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


Look at the two pieces of code:

Doesn't work

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

Works

Me.FieldName2.Value = 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)>
Expert
 
Join Date: Jun 2007
Location: Derbyshire, UK
Posts: 347
#3: Nov 21 '08

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


Quote:

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).Properties.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.Value = 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.Value = True

Me.Controls("FieldName2") = True

Dim intcount As Integer
intcount = 2

Me.Controls("FieldName" & intcount) = True


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



MTB
Newbie
 
Join Date: Nov 2008
Posts: 2
#4: Nov 21 '08

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


Quote:

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.Value = True

Me.Controls("FieldName2") = True

Dim intcount As Integer
intcount = 2

Me.Controls("FieldName" & 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.Properties("Value") = xxx" instead of directly use the syntax "FieldName.Value = 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
Reply