Append a variable value to control name

J

jsteeves

I want to procedure that accepts an integer and appends the integer to a
control name in the code. Ex. of what I have:

Dim WhereMETH1 As String

WhereMETH1 = " SELECT lstTests.meth" & _
" FROM lstTests" & _
" WHERE lstTests.desc = """ & Me.cbotdesc1 & """" & _
" GROUP BY lstTests.meth;"

Debug.Print WhereMETH1

Me.cbotmeth1 = "" 'Clear cbo
Me.cbotunit1 = "" 'Clear cbo
Me.cbotunit1.RowSource = "" 'Clear cbo
Me.cbotunit1.RowSource = "" 'Clear cbo
Me.cbotmeth1.RowSource = WhereMETH1

-------

Dim WhereUNIT12 As String

WhereUNIT12 = " SELECT lstTests.unit" & _
" FROM lstTests" & _
" WHERE lstTests.desc = """ & Me.cbotdesc12 & """" & _
" AND lstTests.meth = """ & Me.cbotmeth12 & """" & _
" GROUP BY lstTests.unit;"

Debug.Print WhereUNIT12

Me.cbotunit12 = "" 'Clear cbo
Me.cbotunit12.RowSource = WhereUNIT12



The only difference is going to be the event which the procedures are bound
to, and the # suffix of the combo boxes. Could I do a procedure like-

public sub cbocascade(intNumber As Integer)

And append intNumber to the control names somehow? I need to do this to
about 15 controls and the way I have it set up lacks finesse.
 
M

Michel Walsh

Hi,


use the Me.Controls( stringNameOfTheControl ) syntax, rather than
Me.NameOfTheControl, or Me!NameOfTheControl :



Me.Controls("cbotunit" & i ).RowSource = ....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top