Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2007, 06:50 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ayaz,

Looks like the problem is in your SQL.
When using grouping, you need to perform "aggregate" functions on all the query fields (SUM, MAX etc) that are NOT in the GROUP BY clause.

In your SQL, you have the "SDate" field on its own. If you want to group things by year/month, then use the following SQL:
Code:
Dim sql as String
sql = _
    "SELECT Sum([TotalValue] AS [SumOfTotalValue]" & VbCrLf & _
    "FROM [Orders]" & VbCrLf & _
    "WHERE [Orders].[OrderDate] BETWEEN #" & SelectedYear & "# AND #" & PreviousYear & "#" & VbCrLf & _
    "GROUP BY (Year([SDate]), Month([SDate])-1)

With GraphSales
    .RowSourceType = "Query"
    .RowSource = sql
    .Requery
End With
I think that should do the trick. I haven't tested this code though so be warned!

Regards,
Rob







Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Access Form Bind With OO4O MTForm Access VBA 4 February 27th, 2008 04:29 PM
ms access form as criteria on sql server backend ottos13 Access 1 September 13th, 2006 12:14 PM
problem using ADO to open form in MS Access apike VBScript 3 May 2nd, 2006 06:25 AM
Microsoft Web Browser used in MS Access Form jeff1804 Access 8 December 9th, 2005 07:17 PM
instantiate a form object by its name in MS Access sky2000 Access VBA 1 May 6th, 2004 03:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.