Use Contents of Variable as field name

R

rmcompute

I am trying to use the contents of a variable as a field name. I set up some
test code as listed below to try to display the contents of field
cboRptPeriod. The first MsgBox displays the contents of that field, however,
the second Msgbox displays the text Me.cboRptPeriod instead of the contents
of the field. Is there a way to do this with a variable?

Private rmtest()
rmtest1 "cboRptPeriod"
End Sub

Sub rmtest1(strFieldTest)
MsgBox Me.cboRptPeriod
MsgBox "Me." & strFieldTest
End Sub
 
A

Allen Browne

Try:
Me(strFieldTest)

That's actually short for:
Me.Controls(strFieldTest)
or possibly:
Me.Fields(strFieldTest)
 
R

rmcompute

It Worked! Thank you.

Allen Browne said:
Try:
Me(strFieldTest)

That's actually short for:
Me.Controls(strFieldTest)
or possibly:
Me.Fields(strFieldTest)
 

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