• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

Dynamic Reporting in Access


I am trying to do a dynamic reporting program in access.  The scope is there are two main tables Staff and Projects.  These tables have a lot of joins to other tables.  The user needs to be able to view the Field names in these tables and choose which fields they would like to see in a report (this is being exported into excel).  I have a form which displays staff members so they pick the staff member or members (this is stored in global variables).  A form then displays a listbox with a list of the fields available from the tables they have chosen.  I have then written code to put the field names and corresponding table names into a table.

I am now trying to write code to build a SQL statement to get the data they require using the staff ids stored in variables and then the field and table names stored in a table.  I will then need to write in the joins and maybe create a table containing all this info to export to excel.

Does anyone have any suggestions on this last bit?  I am on a very tight deadline (end of week!) and I am working from home whilst looking after a baby so finding it all quite hard!

Thanks so much in advance
1 Solution
Hi, how much SQL Server experience do you have?

you will probably need to use the various information schemata schemas, or the systables and sysobjects schemas, to get the table and column names, and then use dynamic SQL on the server to run the queries. An example is:
select sc.name
from sysobjects so
INNER JOIN syscolumns sc ON sc.id = so.id
WHERE            so.name='Employees'
select column_name from INFORMATION_SCHEMA.COLUMNS
WHERE  table_name='Address'

This will list the column in employees or the address table.
Note however that your queries can always return more columns that the user specified and then get Access to not display those columns, the complicated part is in the where condition - when there are different data types -eg dates, integers and strings.
Also you can use SQL views for commonly needed reports which would already have much of the formatting and columns you require.

Anthony PerkinsCommented:
>>I am trying to do a dynamic reporting program in access.<<
Has this got anything to do with SQL Server?
Jeffrey CoachmanMIS LiasonCommented:

While what you are asking can certainly be done, it may not be considered "Easy" for a beginner.

So again, you must have a good working knowledge of MS Access, VBA, SQL, Query Design and Form design.

If this is really crunch time, then you may wish to simply have the users build the queries themselves, selecting the fields they want.
Then provide a combobox to list which queries they want to export.
The write the export code to reference the combobox value
      DoCmd.TransferSpreadsheet acExport, , Me.cboQuery, "C:\YourFolder\Export.xls", True

Here is a sample.

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

WhatwasIthinkingAuthor Commented:
thanks for all your tips.  i have now completed this project with a combination of vbscript and sql queries.
thanks again
Jeffrey CoachmanMIS LiasonCommented:
Isn't that what jmreidy suggested and posted an example of?
I don't think this was SQL server related, the author mentioned SQL, but not SQL server.
It sounds like the solution was MS Access related.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now