• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 621
  • Last Modified:

VBA string to command

Is it possible to convert a string into an actual command, for example if I have a table with a field called Age and I use in vba MsgBox rst!age, could I use a string i.e. MyString = "rst!age" then do something like MsgBox MyString. I know that would just give a message box saying "rst!age" but is there a way to convert that string into a command?
0
Dave01
Asked:
Dave01
  • 3
1 Solution
 
TextReportCommented:
You can use the EVAL() to evaluate it but not sure abour the equivelant of Call parameter.

Cheers, Andrew
0
 
Dave01Author Commented:
It looked promising, but did not work for rst!age, came back with an error saying "can't find name 'rst'  you entered in the expression." :(
0
 
Dave01Author Commented:
Basically I want to create a string with rst!<field name> then use that later on in my code. For example:

FieldName = "age"

MsgBox rst!FieldName

I know the above will not work but thats what I am trying to achieve, the field name is stored in a string so it can be easily changed later on.
0
 
yossigordinCommented:
Hi Dave01
The answer will surprise you.It is very simple:
instead of writing rst!<field name>, write:
rst.Fields(FieldName).
I use it a lot.
Hope it helps,
yossigordin
0
 
Dave01Author Commented:
Thanks yossigordin! It works a treat :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now