Solved

Open Access Report using varying columns

Posted on 2012-04-10
2
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

710 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