Solved

Converting Todays Date to Julien date.

Posted on 2004-09-04
15
7,551 Views
Last Modified: 2012-08-13
I have a field in my table that is called OrderNo.  This order number is based on todays date.  Only the user has to look at a table to figure out what todays date is in Julien and thn they add a sequential number to the end.  Like if today was Jan 1st and this was the first record for the day the Order no. would be 001-001  and if it was the second record of the day then it would be 001-002 and so on until the next day then it would be 002-001.  Make sense?

Is there any VB code that could do this.  I am using Access 2003.

Thanks
John
0
Comment
Question by:John Sheehy
  • 7
  • 5
  • 2
  • +1
15 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 400 total points
ID: 11982246
I have no idea what a Julien date is - do you mean a Julian date?

As for generating the order number, you can use the function I posted here to do it:
http://www.experts-exchange.com/Databases/MS_Access/Q_20525867.html

You have to work out the first part (the part based on the date).
0
 
LVL 12

Assisted Solution

by:fulscher
fulscher earned 100 total points
ID: 11982315
From your example, I assume that with "Julien date", you mean the number of the current day in the year. To find this date, you can use the DateDiff function as follows:

DateDiff("d", "01-01-2004", Date) + 1

to create the format required, you can use

format(DateDiff("d", "01-09-2004", Date) + 1, "000")

To find the correct record number, you have to check whether there are already records in the table for this date and you have to find the higest record number already used. As Shane has pointed out, he has a nice description of how this can be done in his article.

Hope this helps
Jan

Btw: Juilan dates: From http://aa.usno.navy.mil/data/docs/JulianDate.html:

"Julian dates (abbreviated JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BCE (on the Julian calendar). Almost 2.5 million days have transpired since this date. Julian dates are widely used as time variables within astronomical software. Typically, a 64-bit floating point (double precision) variable can represent an epoch expressed as a Julian date to about 1 millisecond precision. Note that the time scale that is the basis for Julian dates is Universal Time, and that 0h UT corresponds to a Julian date fraction of 0.5. "
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982328
I'd add that if you want to find the current day of the year, you can just use:
DatePart("y",Date())

i..e.:
Format(DatePart("y",Date()),"000")

So you could call my function with:
CreateAutoNumber(Format(DatePart("y",Date()),"000") & "-",3)

Thanks for clarifying the Julian date thing Jan - I know what a Julian date is but I couldn't for the life of me work out why you'd want to number your invoices by counting the days from 4713BCE :-)
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 11982357
check this link if it would help in what you are trying to do

How to Convert Julian Days to Dates in Access and Back

http://support.microsoft.com/?kbid=209922
0
 
LVL 12

Expert Comment

by:fulscher
ID: 11982367
Just for clarification: If your reference date (i.e., the date when you start counting) is NOT in the current year, but in the last year, you should use the DateDiff function. If your reference is always the current year, you can use DatePart (which might be even a bit faster).

Things to watch:
- Users enters data in 2004-01-02, but the data concerns a business activity of 2003-12-31; how do you handle this?

- How do you handle multiple years of data? The keys will be the same...

Shane: Good idea, thanks.
0
 

Author Comment

by:John Sheehy
ID: 11982482
Shane,

I need a bit more help with undertsanding this:

Set rst = CurrentDb.OpenRecordset("SELECT Max([AccountNumber]) As MaxAccountNumberFROM tblCustomers WHERE [AccountNumber] Like " & Chr(34) & strPrefix & "*" & Chr(34))
If IsNull(rst!MaxAccountNumber) Then
   strAutonumber = strPrefix & Format(1,String(lngDigits,"0"))
Else
   strTemp = Mid$(rst!MaxAccountNumber
,Len(strPrefix)+1)


I understand the you are Selecting the MAX number from the field AccountNumber in the Table tblCustomer Where [AccountNumber] is like ????

But what is :
" & Chr(34) & strPrefix & "*" & Chr(34))

If it helps my table is tblAwards and the field is OrderNumber.
Sorry for the inconvenience in having to explain this to me.  I just need lame man terms.

Thanks
John


0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982491
No problems John. The bit that you're referring to selects all records where the first part of the field is the same as the string that has been passed. If I can give an example, if you want to create a number starting 002-, you first have to check how many records already start with 002-, so you can determine what the following 3 digits should be.

You need to change the Set rst line to reflect your own field names, i.e.:
Set rst = CurrentDb.OpenRecordset("SELECT Max([OrderNumber]) As MaxAccountNumberFROM tblAwards WHERE [OrderNumber] Like " & Chr(34) & strPrefix & "*" & Chr(34))

I've left the MaxAccountNumber alias in as the rest of the code uses that.
0
 

Author Comment

by:John Sheehy
ID: 11982517
I liked your explanation.

=CreateAutoNumber(Format(DatePart("y",Date()),"000") & "-",3)

So I could place the above statment on the propertied sheet as the default for the filed Order Number

Right ?

John
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982548
No, you wouldn't set it as a default value - you actually need to call the function in the BeforeUpdate event of the form. One of the things it does is to immediately save the record, in case someone else starts typing in a new record before you finish yours, to ensure that they get the right number.
0
 

Author Comment

by:John Sheehy
ID: 11982590
I do it on the beforeUpdate event of the form or the Field OrderNumber.  How does it know to update the field Order number?

John
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982595
Sorry, I wasn't clear - you need to do it in the BeforeUpdate event of the *form* rather than the control. The function will run as soon as you start typing in some data in your form (that's when the form's BeforeUpdate event fires).
0
 

Author Comment

by:John Sheehy
ID: 11982602
But what tells it to store the data in the field OrderNumber?
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982609
Basically, in the form's BeforeInsert (sorry, it needs to be the BeforeInsert, not the BeforeUpdate) event, you have a line of code like this:
Me!txtOrderNumber=CreateAutonumber(Format(DatePart("y",Date()),"000") & "-",3)

txtOrderNumber is the name of the text box which is bound to the OrderNumber field.
0
 

Author Comment

by:John Sheehy
ID: 11982624
You know you said that in the link above.  Sorry for being a pest about it.

But the code worked Great for me.  I am positive the 100 + people that use this will appreciate the time you and everyone else has put into this problem for me.

As I would love to give the points to everyone else here I am opted to split them with Shane and Jan.  Jan supplied the Date format that helped Shane out while helping me out.

Thanks to everyone here

John
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11982633
No problem John, glad I could help!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question