Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 August 10th, 2006, 05:51 PM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Help creating calculation in Access

I need to create a calculation in Access (unk whether to put it in my query, table, report, etc.) and need to know calculation.
I have a report that shows the year (from 1997 - 2006) and two more columns giving me the total # of events each year and total # of attendees each year, what I need is a column after each "total #.." columns telling me what the percentage increase is. I know the darn calculation in Excel but just don't remember Access that well. Please help, thank you.
 
Old August 11th, 2006, 06:45 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Do you want percent increase from one year to the next?

I would be inclinced to create a second table to store the calculated data in, and run a process on your initial data to calculate the values.

The psuedo code would be:

Set warnings to false
DoCmd delete query on second table
Set warnings to true

Open connection to database

Open recordset on this first query you have done that totals the data.

Do until rs.eof

Open recordset on second table for updating.

Pass data from first record to second table
 (do not add percent change)
   Store the data from record in variables.
        iEventsCur - current year event value
        iEventLast - previous year event value
        iAttendCur - etc
        iAttendLast - etc
     If recordset <> first year (1997) then
       Calculation to compare data from current record in loop to last record in variable
       rs1.AddNew
       rs1("Year") = rs("Year")
       rs1("Events") = rs("Events")
       rs1("Attend") = rs("Attend")
       rs1("EventChange") = lgEventCalc
       rs1("AttendChange") = lgAttendCalc
       rs1.Update

     End If
     Pass current records values to Last Year's variables for comparison in next loop.
     iEventLast = iEventCur
     iAttendLast = iAttendCur
rs.MoveNext
Loop

'----------------

Then run your report based on this second table.

It seems like a longer way around perhaps, but it is more robust than detail section calculations, global variables, and modules. Since the code is attached to the button running the report, it is dynamic, and less subject to breakage.

Does this help? I can help with the actual code if you have table structures, field names, etc.

HTH

mmcdonal
 
Old August 11th, 2006, 06:45 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

That's (Do not add percent change) for first year only.


mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculation in access ashik112 Access 1 February 26th, 2007 08:38 AM
Creating TimeSlots in Access Lavagirl69 Access VBA 2 February 5th, 2007 06:21 PM
Access Workdays calculation doug.hall Access 1 April 26th, 2005 02:19 PM
Field Calculation Upgrade to VBA from Access Basic Pavesa Access VBA 2 December 23rd, 2003 12:24 PM
Creating Charts in access smartgir Access VBA 1 October 23rd, 2003 03:25 PM





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