field name substitution in Visual Basic

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

One of my favorite functions in the old Dbase program was the "macro
substitution" function (it was &). To quote the reference manual "This
function is used to obtain the contents of a character memory varaible when
dBase expects a literal value rather than a character expression."

It enabled you to use a memory variable for a field name. For instance, if I
had a table with a field named "Jones", I could access that field (for
editing, etc) by using a memory variable whose value was "Jones." In Visual
Basic syntax it might look like rsNames(strLastname) = 1 (where rsNames has a
field called "Jones" and the variable strNames has a value of "Jones"). I
tried using chr(34) around the variable, but that did not work.

I cannot find a similar function in Visual Basic. And would like to know how
I can accomplish the same result.
 
There is no direct equivalent. You can ***bind*** a Form's control with a
field, though, and changing the Value of the control will eventually change
the value in the record (and save it in the database when the 'dirty' record
will be saved). Note that the Value property of a control is the default
property of a control. To BIND the control to a field, assign its Control
Source property (or even easier, drag the field from the Fields List onto
the detail section of the Form, and Access will create the binded control
for you).



Vanderghast, Access MVP
 
You can use a string variable to represent afield, form etc.....

So, you can go:

strFieldName = "CompanyName"

debug.print rstMyDataTable(strFieldName)

On a form, you can use

me(strFieldName)

So, having come from dBase and FoxPro background, the above syntax gives me
a similar ability to reference fields names that are in a string
expression....
 
Hi Frank,

I started with dBase II and went through Clipper summer 87 (great stuff for
their time).

The closest thing you will find to the macro function in Access is Eval()

Look in the VBA help File.

Regards

Kevin
 
Back
Top