Using a variable for a field name in VBA

  • Thread starter Thread starter Darren
  • Start date Start date
D

Darren

I have a crosstab query in Access 2003 VBA in which the columns in the
query are variable based on user input from a form. The columns are a
combination of year and quarter (2003_1, 2003_2, ...). The query
displays 5 quarters of data at a time. How can I refer to each of
these columns with a variable???

What I have done thus far does not work:
DataPoint1="2003_1"
DataPoint2="2003_2"
....
blah blah = oRST1![DataPoint1]

When this runs I get "Item not found in the collection"

I have tried setting the DataPoint variables as strings, fields to no
avail.

Would appreciate any help I could get on this.
Thanks.
 
Try:
oRST1(DataPoint1)

Since Fields is the default collection for a recordset, that is interpreted
as:
oRST1.Fields("2003_1")
 
What I have done thus far does not work:
DataPoint1="2003_1"
DataPoint2="2003_2"
...
blah blah = oRST1![DataPoint1]

Try

oRST1.Fields(DataPoint1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top