Results 1 to 7 of 7
  1. #1
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91

    Subreport with date criteria that can generate reports

    Hi,


    I have a subform on my main form that displays overall figures for amount spent in each of different catagories. The user can change the date criteria to update the months and year that can be displayed.

    I want to have a button below this that generates a report based on the results from the subform. I'm trying to make this future proof and each text box in the subform uses a different query to get its values. This can be up to 10 different queries for a subform. So How do I get this to display in the report without a major amount of work.

    Is there a simple way to do this?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    How does each textbox use a different query?
    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
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    Sorry misinfo. It uses a different sql statement to total the values

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Still not following. Show example of textbox ControlSource.

    If you want to provide db, follow instructions at bottom of my post.
    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.

  5. #5
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    Sorry for late reply. Looking back over my code i realised I had not even written the VBA code completely. The control source code for the text box is written into the control source box below to give the user a default value
    Code:
    =Nz(DSum("[Amount]","Expenses","[Expense Type]=1 And [InvoiceDate]>=DateSerial(Year(Date()), 1, 1)"),0)
    The user can then use combo boxes to set the start and end month and year. I check for input errors and then I want to change the control source to display the total value between the two dates. Here is where I run into problems. This is the VBA I've been messing with to try and change the control source but I'm stuck now.

    Code:
    Me.txtTotalAdvertising.ControlSource = "Nz(DSum("[Amount]", "Expenses", "[Expense Type]=1 And [InvoiceDate]>=" _
                                    & Me.txtExpensesStartDate.text & "[InvoiceDate]<=" & Me.txtExpensesEndDate.text & ")""
    This throws an error about brackets which I'm working on but I'm not sure if this will actually produce the desired result or if it is possible to change the control source like this.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Okay, that helps my understanding. Not exactly an SQL statement - this is domain aggregate function. Maybe the VBA is not needed. Try:

    =Nz(DSum("Amount", "Expenses", "[Expense Type]=1 AND [InvoiceDate] BETWEEN #" & Nz([txtExpensesStartDate],1/1/1900) & "# AND #" & Nz([txtExpensesEndDate],12/31/2900) & "#"))
    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.

  7. #7
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    Brilliant as always June. Thanks for this. It works with all the error checking I had entered and everything.

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

Similar Threads

  1. Replies: 5
    Last Post: 08-24-2013, 02:07 AM
  2. Replies: 1
    Last Post: 08-02-2012, 04:06 PM
  3. Generate reports by frequency
    By MFS in forum Programming
    Replies: 2
    Last Post: 11-18-2010, 08:09 AM
  4. using a Form with combo boxes to generate reports
    By mistervelasco in forum Access
    Replies: 2
    Last Post: 10-28-2009, 03:38 AM
  5. Replies: 1
    Last Post: 03-11-2006, 07:38 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