Report underlying query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phill86
    New Member
    • Mar 2008
    • 121

    Report underlying query

    Hi

    I have a report with an underlying query. The criteria in the query points to three different controls on a form. The user has to select client name, start date and end date. I want to be able to let the user select just the client name, and not the start and end dates, then run the report, as well as selecting client name, start and end date. Is this possible?

    Regards Phill
    Code:
    SELECT T_ClientDetails.ClientID AS T_ClientDetails_ClientID, T_ActiveSession.SessionID, T_ActiveSession.ClientID AS T_Session_ClientID, T_ClientDetails.FirstName, T_ClientDetails.LastName, T_ClientDetails.Title, T_ClientDetails.OrganizationName, T_ActiveSession.ProjID, T_ArtistProj.ProjBandName, T_Studio.StudioName, T_Studio.StudioDesc, T_ActiveSession.StartDate, T_ActiveSession.EndDate, T_ActiveSession.StartTime, T_ActiveSession.EndTime, T_SessRate.Rate, T_ActiveSession.SessComplete, DateDiff("n",[starttime],[endtime]) AS DateDiffEXP, [datediffexp]\60 & Format([datediffexp] Mod 60,"\:00") AS DateDiffFormatExp, [Rate]/60*[datediffexp] AS TotalExVATExp, Round([vatvalue]/100*[TotalExVATExp],2) AS VATExpr, [TotalExVATExp]+[VATExpr] AS TotalIncVATExpr, T_VATValue.VATValue, T_ArtistProj.ProjectDesc
    FROM T_VATValue, T_ClientDetails INNER JOIN (T_Studio INNER JOIN (T_SessRate INNER JOIN (T_ArtistProj INNER JOIN T_ActiveSession ON T_ArtistProj.ProjBandID = T_ActiveSession.ProjID) ON T_SessRate.SessRateID = T_ActiveSession.SessRateID) ON T_Studio.StudioID = T_ActiveSession.StudioID) ON T_ClientDetails.ClientID = T_ActiveSession.ClientID
    GROUP BY T_ClientDetails.ClientID, T_ActiveSession.SessionID, T_ActiveSession.ClientID, T_ClientDetails.FirstName, T_ClientDetails.LastName, T_ClientDetails.Title, T_ClientDetails.OrganizationName, T_ActiveSession.ProjID, T_ArtistProj.ProjBandName, T_Studio.StudioName, T_Studio.StudioDesc, T_ActiveSession.StartDate, T_ActiveSession.EndDate, T_ActiveSession.StartTime, T_ActiveSession.EndTime, T_SessRate.Rate, T_ActiveSession.SessComplete, T_VATValue.VATValue, T_ArtistProj.ProjectDesc
    HAVING (((T_ClientDetails.ClientID) Like [Forms]![F_ClientSessDRange].[combo7]) AND ((T_ActiveSession.StartDate)>=[forms]![f_ClientSessDrange]![BeginDate] And (T_ActiveSession.StartDate)<=[forms]![f_ClientSessDrange]![EndDate]) AND ((T_ActiveSession.SessComplete)=True));
    Last edited by NeoPa; Feb 26 '09, 01:52 PM. Reason: Punctuated to render comprehensible. Punctuation is a courtesy to all the readers. Not really optional.
  • phill86
    New Member
    • Mar 2008
    • 121

    #2
    Also is there a way to view all the clients so in the combo box there would be a record that says All Clients

    Cheers Phill

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Try replacing line #4 with :
      Code:
      HAVING ((T_ClientDetails.ClientID Like [Forms]![F_ClientSessDRange].[combo7])
         AND  (T_ActiveSession.StartDate Between Nz([Forms]![f_ClientSessDrange]![BeginDate],#1/1/1900#)
                                         And     Nz([Forms]![f_ClientSessDrange]![EndDate],#12/31/9999#)
         AND  (T_ActiveSession.SessComplete))

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        Alternatively, it's possible to open a Report, specifying a WhereCondition parameter that filters it on-the-fly.

        For the record, I suggest you clear the date and client filtering from the query itself, and build a string dynamically in your code.

        Comment

        • phill86
          New Member
          • Mar 2008
          • 121

          #5
          Thanks Neopa great help

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32661

            #6
            Originally posted by phill86
            Also is there a way to view all the clients so in the combo box there would be a record that says All Clients

            Cheers Phill
            Yes.

            If you specify the RecordSource of the ComboBox as having an extra column which is set to be the default returned value of the control, but is not visible, You would need to ensure the value matching the "All Clients" entry is set to "*".

            Comment

            • OldBirdman
              Contributor
              • Mar 2007
              • 675

              #7
              Also is there a way to view all the clients so in the combo box there would be a record that says All Clients
              I'm assuming the ComboBox has 2 columns, ID and Name, that ID is a key. and you mean row, not record, in "...be a record that...". The following SQL statement illustrates how such a combo might be filled. The WHERE clause is for illustration, and might not be needed.
              Code:
              SELECT tClients.Key AS ID, tClients.Name AS Name
              FROM tClients
              WHERE (((tClients.Key)<10)) UNION SELECT -1 AS ID, "<<Select All>>" AS Name FROM tClients ORDER BY Name;
              Test for combobox.value = -1 to see if "<<Select All>>" chosen.

              Comment

              Working...