Calling a control name from a listbox

rikklaney1

Registered User.
Local time
Today, 14:24
Joined
Nov 20, 2014
Messages
157
I am trying to set the backcolor of a control based on whether or not that control shows in a list but I am getting stuck. I get a cannot find field error when I run it. Any idea what I've got wrong?


For x = 0 To 30
'If Me.List61.Column(4, x) = "AM060" Then Me.AM060.BackColor = 255
If Not IsNull(Me.List61.Column(4, x)) Then me.[& list61.Column(4,x) &].BackColor = 255
Next


The second line works so I'm trying to make the third line do the same for the whole form without adding that line of code for each control.
 
I don't understand exactly what you are trying to do in the code you posted but in general to refer to a form's control by it's name you use the form:

Code:
Me(NameOfControl)
for example

Code:
Me.AM060.BackColor = 255

and

Code:
Me("AM060").BackColor = 255

should have the same result
 
Exactly. But rather than type that line for all the controls I would like it to pick up the name out of a listbox column. So if one the rows in column 4 of the list box says "am060" then set the control with that names backcolor to 255.
 
So basically, if there is a value in column 4 then find the control with the same name and turn it red.
 
Steve appears to be offline. He showed you with this:

Me(NameOfControl)

So more specifically try:

Me(Me.List61.Column(4, x))
 
Steve was happy to help. :p
 

Users who are viewing this thread

Back
Top Bottom