?
Solved

VBA string to command

Posted on 2003-03-16
5
Medium Priority
?
614 Views
Last Modified: 2008-02-26
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
Comment
Question by:Dave01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 28

Expert Comment

by:TextReport
ID: 8145935
You can use the EVAL() to evaluate it but not sure abour the equivelant of Call parameter.

Cheers, Andrew
0
 

Author Comment

by:Dave01
ID: 8145945
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
 

Author Comment

by:Dave01
ID: 8145986
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
 
LVL 1

Accepted Solution

by:
yossigordin earned 300 total points
ID: 8146021
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
 

Author Comment

by:Dave01
ID: 8146040
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question