Using different reports for different lines of the same query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • David Scott
    New Member
    • Nov 2011
    • 4

    Using different reports for different lines of the same query

    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.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    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.

    Comment

    • Mihail
      Contributor
      • Apr 2011
      • 759

      #3
      Lets see first if I understand well your request:
      Code:
      For Each Instrument In Query Instruments
          Print the report
      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:
      Code:
      Create a recordset based on your query
      For Each record in recordset
          Select Case InstrumentType
              Case Thermometre
                  DoCmd OpenReportForTermometres Filter:= ThermometreIdentifier
              Case PresureInstrument
                  DoCmd OpenReportForPresureInstruments Filter:= PresureInstrumentIdentifier
              Case .........
                   DoCmd OpenReport....... Filter:= ...........Identifier
              Case Else
                   Some error message
          End Select
      Next

      Comment

      • David Scott
        New Member
        • Nov 2011
        • 4

        #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:

        Code:
        Dim dbCalibraciones As DAO.Database
        Dim rstEquipos As DAO.Recordset
        Dim strSQL As String
        
        Set dbCalibraciones = CurrentDb
        Set rstEquipos = dbCalibraciones.OpenRecordset(CON_FICHAS_BLANCO)
        CON_FICHAS_BLAN CO 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.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32662

          #5
          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.
          Last edited by NeoPa; May 3 '12, 12:05 AM. Reason: Typo

          Comment

          • Mihail
            Contributor
            • Apr 2011
            • 759

            #6
            Sorry but this time my time is very limited.
            Try to put CON_FICHAS_BLAN CO between quotes:

            "CON_FICHAS_BLA NCO"

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

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32662

              #7
              Originally posted by Mihail
              Mihail:
              Try to put CON_FICHAS_BLAN CO between quotes:
              That would certainly be necessary David. Otherwise VBA will be looking for a variable called CON_FICHAS_BLAN CO.

              Comment

              Working...