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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i use a variable to refer to a field in a table

Status
Not open for further replies.

Razor1

IS-IT--Management
Nov 21, 2002
81
US
I am reading from one table and adding a record in another. One of the fields in the table a is used to determine what field to place the data in the second table.

Example: Table1 has a value in Field Name:Location
The value in that location is "WP"

Table2 has a field named WP. I need to place data in Table2 Field:WP.


Any help will be greatly appreciated.

Thanks in advance.



Razor1
 



Hi,

"Table2 has a field named WP"

Fields named as DATA is ususally a RED FLAG. It is NOT a "best and accepted practice" in database design.

That being said, if you use ActiveX Data Objects (ADO) to query and update...
Code:
recordset2.fields(recordset1.fields("Location").value).value


Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Thanks for the quick response.

I think you misunderstood or I was was not clear on what I am trying to accomplish.

I do not have any fields name data. I am aware that is is a bad practice.

The value in a field in table1 is a reference to a field in table2.

Table1!loc = WP (this value refers to a field in Table2)
Table2!WP = a value from a different field in Table1


Table1 Has the following fields:
Loc Qty ItemNo
Record1 WP 5 ABC

The result should be:
Table2 has the following fields:
Item AB CD WP
Record1 ABC 5

Thanks again for any assistance.





Razor1
 



Code:
  for each fld in recordset2.fields
    if fld.name = recordset1.fields("Location").value then
       'houston, we have a hit!
    end if
  next


Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top