Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Visual Basic to indirectly access a database field 2

Status
Not open for further replies.

SteveCop

Programmer
Jan 11, 2002
24
GB
I have a table containing fields Sales1 through Sales12

Using a For-Next loop I want to address the fields sequentially and have established a routine which, on each pass through, sets the contents of a variable at Sales1, Sales2 etc. The variable is called cField

Problem is, how do I address the database field using the contents of cField rather than the literal string cField?

For example, if I use rcdCustomers![cField] the program will look for a field called cField rather than Sales1.

 
Brilliant! How easy was that (and how much time have I wasted this morning before asking!). Many thanks for your help.
 
Actually, rcdCustomers![cField] is an Access specific notation and is equivalent to the VB notation rcdCustomers("cField").
If you drop the double quotes, you can use string variables to refer to fields, or forms, or whatever. The "Access specific" notation does not support this.
Luckily, you can use either solution, depending on what you want to do. I myself will stick to the VB one as it will always work.

Dan

[pipe]
 
Have another star, Dan. I've been trying to figure out how to do the same thing myself for a week now.

The answer's so simple once you know the correct syntax. Maq [americanflag]
<insert witty signature here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top