DatePart() invalid argument??? (1 Viewer)

Agism

Registered User.
Local time
Today, 11:26
Joined
Jun 25, 2001
Messages
44
I am trying to create a "TripID" with the area of the trip and leave date. For example, say you are visiting the West on 7/5/02, I would like the TripID to become West070502.

I have tried DatePart("dd",me.BeginDate) and I get this error:

Run-time Error '5'
Invalid procedure call or argument.

I have also tried Format(me.BeginDate,"dd") & Format(me.BeginDate, "dd") & Format(me.BeginDate,"yy") and received 777.

Anyone know what my problem is?

Thanks in advance!:confused:
 

Tim K.

Registered User.
Local time
Today, 16:26
Joined
Aug 1, 2002
Messages
242
Try this.

Dim TripID As String

TripID = "West"
TripID = TripID & Format(DatePart("d",#7/5/02#),"00")
TripID = TripID & Format(DatePart("m",#7/5/02#),"00")
TripID = TripID & Right(DatePart("yyyy",Me.BeginDate),2)

I wonder what's wrong with Format with you.

I tried it out and resulted like this.

? Format(#7/5/02#,"yy")
02
? Format(#7/5/02#,"dd")
05
? Format(#7/5/02#,"mm")
07

Where are you anyhow? What country?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:26
Joined
Feb 19, 2002
Messages
42,970
Making "intelligent" keys is fraught with problems. I would recommend against it. Use an autonumber as your key and keep two data fields. One for destination or whatever "West" is and one for start date. You will find this structure much simpler to work with for analysis purposes.

If you insist on your present course, use comething like the following:

DateId = Me.SomeField & Format(Me.SomeDate,"yyyymmdd")

Notice that I resequenced the date components and expanded year to 4 digits. My version will at least sort things into some logical order.
 

Agism

Registered User.
Local time
Today, 11:26
Joined
Jun 25, 2001
Messages
44
Pat -

Thank you for your help. I was certain that you would have something for me. I agree with your views on "intelligent" keys. This is just what those in charge wanted to see.

Tim K. - I am in Texas, USA. Thanks for your help!
 

Users who are viewing this thread

Top Bottom