By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,762 Members | 1,836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,762 IT Pros & Developers. It's quick & easy.

Using different reports for different lines of the same query

P: 4
Hi all.

In my company we have a database to keep record of measuring and control instruments f.e. Pressure switchs, Thermometres, Gauges, etc.

Each type of instrument has a different form because the type of data we keep from them varies depending of how it works. Al these forms have a common part where we put the name of the instrument, the facility, serial number, etc. and a different one with the especific technical data for each instrument. We have a corresponding report for each type of form.

To enter data for a new instrument it's easy, the user just selects the type and then he is showed the right form.

The problem is when I want to print all the instruments data from a certain installation, for example. The query will give me as a result many different instruments. When I print the reports I need to launch a different one depending of the instrument type and here is where I need your help.

How to lauch different reports from a single query depending on the intrument type?

If I didn't explain correctly please let me know and I will try to make it clearer. As you surely have seen english is not my first language. :)

Thanks in advance.
Apr 30 '12 #1
Share this Question
Share on Google+
6 Replies

Expert Mod 15k+
P: 31,489
You seem to make fewer errors in your English than many for whom it IS their first language :-D

You do, however, have a pretty complex task in front of you. My advice would be to try to design a report with various controls available. Some fairly complex (although not rocket-science level) code would need to be run at print or format time to ensure that only the controls appropriate for the current object are visible.

Another thought that occurs to me, although I can't promise it will work as it's just a new idea, is to have a subreport control that takes any of the reports designed for your objects and sets the ObjectSource value of the SubReport control to match for each individual object.
Apr 30 '12 #2

P: 759
Lets see first if I understand well your request:
Expand|Select|Wrap|Line Numbers
  1. For Each Instrument In Query Instruments
  2.     Print the report
  3. Next
Is this what you are looking for ?

If the answer is YES I think that is an easy task:
Also in pseudo-code that must look like:
Expand|Select|Wrap|Line Numbers
  1. Create a recordset based on your query
  2. For Each record in recordset
  3.     Select Case InstrumentType
  4.         Case Thermometre
  5.             DoCmd OpenReportForTermometres Filter:= ThermometreIdentifier
  6.         Case PresureInstrument
  7.             DoCmd OpenReportForPresureInstruments Filter:= PresureInstrumentIdentifier
  8.         Case .........
  9.              DoCmd OpenReport....... Filter:= ...........Identifier
  10.         Case Else
  11.              Some error message
  12.     End Select
  13. Next
May 1 '12 #3

P: 4
Thank you both for your answers.

I think that what I need is exactly what Mihail says, a Select Case that goes through all the instruments launching the right report depending on its type.

The problem is that I'm having trouble implementing it and as I still have very little experience with VBA and SQL I can't find the error.

From what I've found googling this is the way to create a recordset from my query:

Expand|Select|Wrap|Line Numbers
  1. Dim dbCalibraciones As DAO.Database
  2. Dim rstEquipos As DAO.Recordset
  3. Dim strSQL As String
  5. Set dbCalibraciones = CurrentDb
  6. Set rstEquipos = dbCalibraciones.OpenRecordset(CON_FICHAS_BLANCO)
CON_FICHAS_BLANCO is a query that gives me all the instruments from a selected facility.

This returns me the error 3061 saying that they are too few parameters and that 1 was expected.

What i am doing wrong?

Thank you very much for your patience.
May 2 '12 #4

Expert Mod 15k+
P: 31,489
That may certainly prove an easier approach to get your head around David. I'll continue to follow anyway, in case I can be of further help.
May 2 '12 #5

P: 759
Sorry but this time my time is very limited.
Try to put CON_FICHAS_BLANCO between quotes:


If steel don't work inform me and I'll try, tomorrow, to give you more assistance.
May 2 '12 #6

Expert Mod 15k+
P: 31,489
Try to put CON_FICHAS_BLANCO between quotes:
That would certainly be necessary David. Otherwise VBA will be looking for a variable called CON_FICHAS_BLANCO.
May 3 '12 #7

Post your reply

Sign in to post your reply or Sign up for a free account.