473,765 Members | 1,966 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Current and Previous Date

57 New Member
Not sure how to begin with this one. My table consists of:

Expand|Select|Wrap|Line Numbers
  1. Branch# (number, double) 
  2. EntryDate (datetime, mm/dd/yyyy hh:mm:ss am/pm)
One branch can have many entry dates (i.e, Branch # 76 has 10 entry dates).

I'm trying to show the most recent entry date & the previous entry date on a report. I know how to get the most recent entry date using Max. How would I get to the previous entry date? (Current is 2/14/2008 2:26:07 PM and the one before that is 1/30/2008 12:25:58 PM).

(or even a ranking would do i.e, Branch 76 would have a ranking of 1-10 based on entry_date and I could use 1 as current and 2 as previous).

I might mention that there are multiple branch #'s and I need to get the current & previous entry date for each branch (or rank by entry date for each branch).

Any help is appreciated!
Apr 8 '08 #1
2 4183
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. The branch dates can be obtained using two relatively simple queries. Open the Access query designer, select View, SQL View and Paste in the first SQL query below. Change the name of the [BranchEntries] table placeholder to the name of your actual table throughout, save the query under the name BranchMaxEntry.

Paste the SQL for the second query, again changing the name of the [BranchEntries] table to the actual name you are using. Save this under the name BranchCurrentDa tes.

You can then add this query to your report query and join it on the branch#. This will repeat on all rows the previous and latest entry dates. You are then able to add these to whatever part of your report is best.

Please note that if a branch has just one date entry it will not show in the BranchCurrentDa tes query. For this reason you may have to use a left-join with your report query in order to preserve entries for branches with just one date.

Test data shown below.

Hope this helps.

-Stewart

Query BranchMaxEntry
Expand|Select|Wrap|Line Numbers
  1. SELECT [BranchEntries].[Branch#], Max([BranchEntries].EntryDate) AS MaxEntry
  2. FROM [BranchEntries]
  3. GROUP BY [BranchEntries].[Branch#];
Query BranchCurrentDa tes
Expand|Select|Wrap|Line Numbers
  1. SELECT [BranchEntries].[Branch#], Max([BranchEntries].EntryDate) AS [Prev Entry], BranchMaxEntry.MaxEntry AS [Latest Entry]
  2. FROM [BranchEntries] INNER JOIN BranchMaxEntry ON [BranchEntries].[Branch#] = BranchMaxEntry.[Branch#]
  3. WHERE (((BranchMaxEntry.MaxEntry)<>[EntryDate]))
  4. GROUP BY [BranchEntries].[Branch#], BranchMaxEntry.MaxEntry;
Test Data (uk date format shown - dd/mm/yyyy)
Expand|Select|Wrap|Line Numbers
  1. BranchEntries Table
  2. Branch#..EntryDate
  3. .76......01/03/2008
  4. .76......15/03/2008
  5. .76......04/04/2008
  6. 100......10/03/2008
  7. 100......05/04/2008
  8. 110......01/04/2008
  9. 110......03/04/2008
  10. 110......05/04/2008
  11. 110......08/04/2008
  12.  
  13. BranchmaxEntry Query
  14. Branch#..MaxEntry
  15. .76......04/04/2008
  16. 100......05/04/2008
  17. 110......08/04/2008
  18.  
  19. BranchCurrentDates Query
  20. Branch#..Prev Entry...Latest Entry
  21. .76......15/03/2008...04/04/2008
  22. 100......10/03/2008...05/04/2008
  23. 110......05/04/2008...08/04/2008
Apr 9 '08 #2
DThreadgill
57 New Member
Thank you so much!!! I haven't had the chance incorporate into my database but will let you know the results!
Apr 9 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4710
by: AAVF | last post by:
I have a small table that need to keep a balance of work outstanding. The fields are as follows REC_COUNT (auto-index created record counter) DATE (work date) QTY_REQD (work added on that date) BAL (balance of work outstanding at the end of that date) The field REC_COUNT is used as a sort order field so that there is no confusion about which record is next.
4
20988
by: | last post by:
Something really common I'm sure and I'm surprised it's not just a field property option. The previous record's field value can be retrieved and copied into the current corresponding field by the operator hitting CTRL+APOSTROPHE on the new field but I would like this to occur with the user having to strike any keys. Suggestions?
3
16516
by: jannoergaard | last post by:
Hi I want to write a function that can return a sum for a given date range. The same function should be able to return the sum for the same period year before. Let me give an example: The Table LedgerTrans consist among other of the follwing fields AccountNum (Varchar) Transdate AmountMST (Real)
3
5305
by: laryten | last post by:
Hi, Is there a way to update the same web page instead of getting a new page each time we click the submit button? The simplest thing to do is to delete the current page (or go back to the previous page) and then redraw the page. There are a few possible solutions: 1. Use the same URL again. But a new page will still be created. 2. Use the "onsubmit" option:
1
4341
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same logic for a date field. i.e. theValue.defaultvalue = "#" & theValue.value & "#" I can't get this to work for some reason and I can't figure out why. Can anyone out there help? Thanks Repeat value of previous record field into current...
5
13719
by: Chris | last post by:
I am trying to output Monday of the current week i.e. if Monday is the 8th I want to display 'Monday 8th' for any date between Monday 8-14th. I would appreciate any help, the code below is heading in the right direction but doesn't quite give me the results I am looking for. $givenday = mktime(0,0,0,10,08,2007); $Monday = strtotime("Monday this week",$givenday); echo date("j M Y H:i:s", $Monday);
1
2589
by: tmcjunkin | last post by:
I'm trying to back into this project by defining what the user needs to see when they open a form. I'm between beginner and intermediate with vba, but have been using access for years. When the user opens the form they need to see the resident's current balance. The balance includes: Previous balance (which I can just pull in) Current rent (which needs to be based on the date the form is opened) Late fees (which needs to be based on...
3
7906
by: lyndac | last post by:
Hello! Last night a job to create a view using DATE(CURRENT DATE - 1 DAY) received the current days date instead the previous days date. Any one know why/how this can happen? The DATE(....) is a hold over from when they use a hard coded date. Is that scalar function impacting the result?
3
3018
by: One | last post by:
Hi group - I want to do a SELECT based on a date range - but mySQL syntax expects the month range to be two digits. So I have converted the month to show the leading zero like this : $next_month = date('m')+1; $this_month = date('m'); $pre_month = date('m')-1;
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9399
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9833
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.