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

Generic field variable

Status
Not open for further replies.

Cage

MIS
Aug 25, 2002
50
0
0
CA
Hi, I have the following code

Dim RecordSet As DAO.Recordset
Set RecordSet = CurrentDb.OpenRecordset("Select * from tblGlobalData ORDER BY [Model], [Nationality Group], [Total Revenue Curr PEriod] DESC;")
Total = RecordSet![Total Revenue Curr Period]
Nationality = RecordSet![Nationality Group]
Market = RecordSet![Model]


However I want to create a generic field variable so that I can reuse the code for a number of field e.g

Dim RecordSet As DAO.Recordset
Set RecordSet = CurrentDb.OpenRecordset("Select * from tblGlobalData ORDER BY [Model], [Nationality Group], [" & GenericField & "] DESC;")
Total = RecordSet!GenericField
Nationality = RecordSet![Nationality Group]
Market = RecordSet![Model]

Any idea on how I can do this?

thanks

Cage
 

Dim RecordSet As DAO.Recordset 'Rename this to a non reserved word --> rst?
Dim myGenericField As String
Dim strSQL As String
strSQL = "SELECT * " & _
"FROM tblGlobalData " & _
"ORDER BY [Model], " & _
"[Nationality Group], [" & _
myGenericField & "] DESC;"

Set RecordSet = CurrentDb.OpenRecordset(strSQL)

Total = RecordSet.Fields(myGenericField)
Nationality = RecordSet.Fields("Nationality Group")
Market = RecordSet.Fields("Model")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top