concatenated field names

  • Thread starter Thread starter Steve Arndt
  • Start date Start date
S

Steve Arndt

How can I code something like this

SortOrder1_Combo = rs("Field").Value

where
iValue = 1
"SortOrder" & iValue & "_Combo" = rs("Field").Value

Thanks

Steve
 
Hi Steve,

Not entirely sure of your objective but this code will let you build a name
for a control and I think
you can just reference rs("Field") rather than the .Value being required.
Not positive, but try it. Test code assigns value 8 to the control. (Form
has a control named SortOrder1_Combo and a command
button named Command6.)

Private Sub Command6_Click()
Dim ctl As Control
Dim iValue As Integer
Dim sName As String

iValue = 1
sName = "SortOrder" & iValue & "_Combo"
For Each ctl In Me.Controls
If ctl.Properties("name") = sName Then
ctl = 8
End If
Next ctl
End Sub

HTH
Linda
 
There are several ways to reference a control - "me.MyControl" is the most
common but another very useful syntax is:

me.controls("myControl")

So for your problem:

me.controls("SortOrder" & i & "_Combo") = rs("Field").Value
 
Sandra,

Very elegant. Always learn something new here.

thx
Linda


Sandra Daigle said:
There are several ways to reference a control - "me.MyControl" is the most
common but another very useful syntax is:

me.controls("myControl")

So for your problem:

me.controls("SortOrder" & i & "_Combo") = rs("Field").Value


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Steve said:
How can I code something like this

SortOrder1_Combo = rs("Field").Value

where
iValue = 1
"SortOrder" & iValue & "_Combo" = rs("Field").Value

Thanks

Steve
 
This worked great! Thanks
Steve
Sandra Daigle said:
There are several ways to reference a control - "me.MyControl" is the most
common but another very useful syntax is:

me.controls("myControl")

So for your problem:

me.controls("SortOrder" & i & "_Combo") = rs("Field").Value


--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.


Steve said:
How can I code something like this

SortOrder1_Combo = rs("Field").Value

where
iValue = 1
"SortOrder" & iValue & "_Combo" = rs("Field").Value

Thanks

Steve
 
Back
Top