Solved

Open Access Report using varying columns

Posted on 2012-04-10
2
260 Views
Last Modified: 2012-04-10
I have a table with 25 field names like this:
slot_1
slot_2
slot_3
... slot_25

I have a report that will only need one of the fields at a time.  The report should be formatted like this:
Date:              Slot_(x)
4/10/12           .011
4/10/12           .010
4/10/12           .012

The data in the slot column will vary depending on which slot is being used.

I have the field name from a non visible text box on the form that opens the report.
 
The report is opened like this:
strWhere = "Select Burn_In_Date, " & strSlot
strWhere = strWhere & " FROM Part_Voltage"
strWhere = strWhere & " WHERE (((Part_Voltage.BurnIn_Date) Between [Forms]![frm_rpt_Report1]![txtBurn_In_Start] And DateAdd("
strWhere = strWhere & "'h'"
strWhere = strWhere & ",20,[Forms]![frm_rpt_Report1]![txtBurn_In_Start])));"
DoCmd.OpenReport "rpt_PartVoltage", acViewPreview, strWhere


Can I use a variable for a field name?
Some other way?

Thanks,
Brooks
0
Comment
Question by:gbnorton
2 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 37829566
1.  Not like the way you have it in your example.  The strWHERE clause (which is actually the 4th argument, not the 3rd in the OpenReport method does not accept an entire SQL string, like you have provided.  All it woud accept is the part of the SQL string to the right of the word "WHERE".  So what you need to do is create the SELECT portion of your query, and save that as the SQL string of a query.  To do this,
    a.  Start out by creating a query by using the query grid. When you are done, save the query as qry_rpt_PartVoltage
    b.  Then modify your code above so that after you have completed building the SQL string, you update the SQL property of the query.  Something like:

strSQL = "Select Burn_In_Date, " & strSlot & " as Slot_x " _
           & "FROM Part_Voltage "
           & "WHERE (((Part_Voltage.BurnIn_Date) Between #" & [Forms]![frm_rpt_Report1]![txtBurn_In_Start] & "# " _
           & "And DateAdd('h',20,#" & [Forms]![frm_rpt_Report1]![txtBurn_In_Start] & "#)));"
currentdb.querydefs("qry_rpt_PartVoltage").SQL = strSQL

    c.  Then you don't need to apply the WHERE argument to the report, you just open the report, which has this as your query.

Once you do that, the field in your report will always be referred to as "Slot_x".  So, if I were you, I would also add something to the report which would identify the actual field that was used to generate that report.
0
 

Author Closing Comment

by:gbnorton
ID: 37829682
Thanks a bunch for the prompt solution.
Brooks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now