Link to home
Start Free TrialLog in
Avatar of John Sheehy
John SheehyFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of shanesuebsahakarn
shanesuebsahakarn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :-)
Avatar of Rey Obrero (Capricorn1)
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
Avatar of fulscher
fulscher

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.
Avatar of John Sheehy

ASKER

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


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.
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
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.
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
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).
But what tells it to store the data in the field OrderNumber?
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.
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
No problem John, glad I could help!