Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / May 2006

Tip: Looking for answers? Try searching our database.

Substitution of variable contents in a command

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TerryL - 11 May 2006 13:51 GMT
Some languages allow you to force the interpreter to evaluate the contents of
a variable in a command  before the command is executed.  Is there a way to
do this in VBA.  Here is an example.

The objective is to develop a common routine to apply a set of
transformation rules to the contents of a field in a table.  The name of the
table and the name of the field is supplied to the routine in string
variables.  The table name is not a problem since the OpenRecordSet command
uses a string for the table name.  It is the field name I am having a problem
with.  In the update section the logic looks like:

recordset.Edit
recordset!FieldnameVariable = strfieldvalue
recordset.Update

Where both FieldnameVariable and strfieldvalue are string variables defined
in DIM statements.  The value of FieldnameVariable changes with the table
name supplied.  As the code is presented above, you get an error because
"FieldnameVariable" is not a column name defined in any table.  If the
contents of FieldnameVariable is "ActualFieldName", how can I force VBA to
substitute the variable contents in the command so it looks like:

recordset!ActualFieldName = strfieldvalue

when it gets excuted.
Alex Dybenko - 11 May 2006 14:10 GMT
Hi,
if FieldnameVariable holds a field name - then you can use:

recordset(FieldnameVariable) = strfieldvalue

Signature

Best regards,
___________
Alex Dybenko (MVP)
http://alexdyb.blogspot.com
http://www.PointLtd.com

> Some languages allow you to force the interpreter to evaluate the contents
> of
[quoted text clipped - 27 lines]
>
> when it gets excuted.
TerryL - 11 May 2006 15:36 GMT
That was easy.  Thank you.

> Hi,
> if FieldnameVariable holds a field name - then you can use:
[quoted text clipped - 32 lines]
> >
> > when it gets excuted.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.