Wrox Programmer Forums
|
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 March 11th, 2005, 06:19 AM
Authorized User
 
Join Date: Dec 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default query

Hi All

I need to run a query that calculates the summing of figures within a certain month. The query uses a table that has data for several hundread cost centres, the data being divided over a max of 12 months.I just need the present month. If I prompt the user with the question 'which month do you want' is there a quick way to use one query for the 12 possible months rather than firing off 12 different queries?

eg table

cost centre month1 month2 month3 month4 month5
00001 £300 £200 £150
00002 £259 £600 £160


etc

Cheers
Tony
__________________
Cheers
Tony
 
Old March 11th, 2005, 08:37 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   Create one query that does all 12 months, and then use the user input to select only the month the user selects. I do this in one of my main forms where I have them select a month from one combo box, and then a year from another, and then click a button that calls a report based on a query that selects all data. I use this code on the button's On Click event:

'=====
    Dim stDocName As String
    Dim stMonth As String
    Dim stYear As String
    Dim stLinkCriteria As String

    stMonth = Me.cboMonth
    stYear = Me.cboYear

    stLinkCriteria = "[Month] = " & "'" & stMonth & "'" & " And " & "[Year] = " & "'" & stYear & "'"

    stDocName = "rptMyMonthYearReport"
    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

'=====

   When I built the combo box, I typed in the month values rather than look them up so speed things along. I had to put a On No Data event on the form just in case there was no data for the month.

HTH

mmcdonal
 
Old March 11th, 2005, 08:39 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

BTW, the data in the table you have there is not normalized, but it should speed this process up iof this is just OLAP.

mmcdonal
 
Old March 11th, 2005, 10:17 AM
Authorized User
 
Join Date: Dec 2004
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a mill

Cheers
Tony
 
Old March 11th, 2005, 11:14 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

OLAP? What does this mean? (One Lap Around the Park?)


I’ve always wondered what Microsoft was thinking when they set up the wizards to create
Code:
    Dim stDocName      As String
    Dim stLinkCriteria As String

    stLinkCriteria = "..."
    stDocName = "rptMyMonthYearReport"
    DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria
    It is almost always the case that you use stDocName just one time, so I always change this to
Code:
    Dim stLinkCriteria As String
Code:
    stLinkCriteria = "..."
    DoCmd.OpenReport "rptMyMonthYearReport", acPreview, , stLinkCriteria
    I often replace the LinkCriteria string with a literal as well, although in cases like this one, where the string is pretty long, I often retain the model of setting a string, then using it as an argument.
 
Old March 12th, 2005, 12:32 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 248
Thanks: 0
Thanked 1 Time in 1 Post
Default

I agree with Brian about the excess code. OTOH, if they would just bother to use the excess code in the error trap...

Instead of:

    MsgBox Err.Description
    Resume Exit_Command7_Click

Why not:

    MsgBox "Open form : " & stDocName & " reported error: " & vbCrLf & Err.Description
    Resume Exit_Command7_Click

I suppose they left that out so if we don't want the extra code there isn't so much to clean up. But then again when you're debugging, you can change the value of stDocName without changing the code. Of course this makes more sense for the Link Criteria. So in that sense, the wizard helps.

OLAP, in case you really don't know, On Line Analytical Processing.

Randall J Weers
Membership Vice President
Pacific NorthWest Access Developers Group
http://www.pnwadg.org





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
how to make a query from an existing query raport SQL Language 3 November 13th, 2006 08:59 PM
I solved insert query.now see this Update Query. [email protected] VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





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