Results 1 to 6 of 6
  1. #1
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87

    Sub report based on SQL


    My main report shows data straight from the table - no filter needed. However my subreport should only show data for the month/year entered by the user. I want to use a docmd.runsql in the subreport to do this. Will this work? Will it have any effect on the linked child fields with the main report? (sub report filter will not affect the linked fields between the two).

    Thanks

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Never tried that. If it works, doubt it will affect the linking as long as the link fields are in the RecordSource.

    Think I would use the Filter and FilterOn properties of the subform instead.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87

    Getting an error in sql statement

    Not sure yet if it will work. I am getting an error "....requires an argument consisting of an SQL statement". Do I have a syntax error?

    Here is the code:


    Dim SQLstr As String

    SQLstr = "SELECT CrewInformation.CrewMemberId, tblCompanyExtras.ExtraDate, " _
    & "tblExtras.ExtrasDescription, tblCompanyExtras.ExtraCost, " _
    & "Format([ExtraDate],#mm/yy#) AS extDt, tblExtras.ExtrasCategory " _
    & "FROM tblExtras INNER JOIN (CrewInformation INNER JOIN " _
    & "tblCompanyExtras ON CrewInformation.CrewMemberId = tblCompanyExtras.ExtraWorkId) " _
    & "ON tblExtras.ExtrasId = tblCompanyExtras.ExtraId " _
    & "WHERE (((Format([ExtraDate],#mm/yy#))=Format(Date(),#mm/yyyy#)) AND ((tblExtras.ExtrasCategory) Not Like 's')) " _
    & "ORDER BY tblCompanyExtras.ExtraDate DESC;"


    DoCmd.RunSQL SQLstr

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You don't run a select statement. So RunSQL is not what you want in this case.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    bob is right and I should have noted in reply. SELECT is not an action query so RunSQL isn't applicable. I was probably thinking OpenQuery when I read the post. However, even that will not influence the RecordSource of form.

    What you can do is set the RecordSource property of the form and then Requery.
    Or set the Filter and FilterOn properties.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    TinaCa is offline Advanced Beginner
    Windows Vista Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    87
    thanks guys, I decided to just go with a query statement and set the filter on the command button that opens the report.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. report based on a query
    By blueraincoat in forum Reports
    Replies: 4
    Last Post: 03-27-2011, 03:31 AM
  2. Report based on query
    By asmith in forum Reports
    Replies: 3
    Last Post: 10-07-2010, 10:24 AM
  3. Report based on query + sub-report (1:N relation)
    By BayerMeister in forum Reports
    Replies: 1
    Last Post: 08-19-2010, 03:26 AM
  4. Report based on date
    By Dega in forum Reports
    Replies: 3
    Last Post: 06-11-2010, 10:05 AM
  5. Replies: 1
    Last Post: 02-02-2009, 05:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums