Wrox Programmer Forums
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 December 19th, 2003, 02:20 PM
Friend of Wrox
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default Access Form

Hi Everyone,

I am trying to display a previous day information and calculate the current date information only and display in on a form.

For Example
[u]FieldName</u> [u]Date</u> [u]Difference</u>
1000 12-19-2003 (First Entry) result from previous
1050 12-20-2003 (second Entry) result from previous
1150 12-21-2003 (Last Entry) result from Previous

In the form I will like to only display the previous date information and the current date information. On monday I make my first entry " 1000","12-19-2003" on the tuesday I make my second Entry "1050", "12-20-2003". On the Difference field name I will like to calculate the difference from previous date First entry "1000-Previous entry, second entry "1050-1000" last entry "1150-1050".

I hope that I was descriptive enough to paint a picture. Any help will be greatly appreciated. Remember it must always calculate the previous date entry only. Thanks everyone.

Jaime E. Maccou
Old December 21st, 2003, 05:38 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 308
Thanks: 0
Thanked 0 Times in 0 Posts

If the previous date is always the most recent date before the one you're entering - you could use a DMax to get it. (look up dmax in Access help)


I am a loud man with a very large hat. This means I am in charge
Old December 21st, 2003, 06:01 AM
Authorized User
Join Date: Nov 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts

I hope this will help.

Private Sub Form_Load()
   Dim rsPrevious as recordset
   Dim rsCurrent as recordset
   Dim strSql as string
   Dim lngPrevious as long
   Dim lngCurrent as long
   Dim lngDifference as long

   strSql= "SELECT Field FROM Table WHERE Date = "
   Set rsPrevious = CurrentDb.OpenRecordSet(strSql _
                                        & DateAdd("d",-1,Date()))
   lngPrevValue = rsPrevious!Field

   Set rsCurrent = CurrentDb.OpenRecordSet(strSql _
                                        & Date())
   lngCurrValue = rsCurrent!Field

   lngDifference = lngCurrent - lngPrevious
   txtDifference = lngDifference
End Sub

If you are using a bound form put this code in the Form_current event.

Old December 22nd, 2003, 03:34 PM
Friend of Wrox
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc

I will try this and get back to you with the results.

Similar Threads
Thread Thread Starter Forum Replies Last Post
get outside form access angelboy C# 2005 1 September 10th, 2007 03:57 AM
Access Report from Access PivotTable Form Odeh Naber Access 2 July 24th, 2007 09:33 AM
Access form to web form clott BOOK: Access 2003 VBA Programmer's Reference 0 February 13th, 2006 06:44 PM
Resize Access main window from Access form hasseh Access VBA 2 October 24th, 2004 05:15 PM
A Access Form issue goels Access VBA 6 October 7th, 2004 06:58 AM

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