By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,482 Members | 2,411 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,482 IT Pros & Developers. It's quick & easy.

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

P: 3
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
Nov 21 '08 #1
Share this Question
Share on Google+
3 Replies


missinglinq
Expert 2.5K+
P: 3,532
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)>
Nov 21 '08 #2

Expert 100+
P: 634
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
Nov 21 '08 #3

P: 3
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
Nov 21 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.