Use Contents of Variable as field name

  • Thread starter Thread starter rmcompute
  • Start date Start date
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
 
Try:
Me(strFieldTest)

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