Converting Todays Date to Julien date.

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
Who is Participating?

Commented:
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

Commented:
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

Commented:
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

Commented:
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

Commented:
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

Security AnalystAuthor Commented:
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

Commented:
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

Security AnalystAuthor Commented:

=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

Commented:
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

Security AnalystAuthor Commented:
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

Commented:
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

Security AnalystAuthor Commented:
But what tells it to store the data in the field OrderNumber?
0

Commented:
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

Security AnalystAuthor Commented:
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

Commented:
No problem John, glad I could help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.