Hard Code date

S

Signe

I built a database to track membership in our Club. On the form that I
record payment of dues I manually change the default value the 1st week of
January for the field labeled ‘PdThrough’ e.g. #12/31/2008#.

I want to hard code the PdThrough date to read m/d/yyyy. The year the
receipt was written is always the membership year. I looked at using the
Date Part function but I do not know how to pick up the month and day. I
would appreciate your help.

=Date Part(“yyyyâ€(PymtDate]) Date Receipt is written: PymtDate (date of
receipt)
 
K

KARL DEWEY

I want to hard code the PdThrough date to read m/d/yyyy.
Access only sotres the date one way. All the different formats are display
formats.

Set the format of your display (query, form, or report) the way you want it
to look.
 
J

Jeff Boyce

I'm not clear whether you wish to control the display of a date (if so,
other folks have already discussed this) or wish to control what date is
used.

If the latter, perhaps the DateSerial() function could help.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
S

Signe

I used the following code using the Date Serial. Based on the date of the
receipt (5/1/2008) the PdThrough date should have been 12/31/2008. but Pd
Through date was 12/29/2019. The month and day remain constant only the year
changes.

Private Sub PdThrough_Enter()
Dim D as Integer, M as Integer, Y as Integer

If IsNull (PymtDate) Then
PdThrough = Null
Else
M = 12
D = 31
Y = DatePart(“yyyyâ€,[PymtDate])
PdThrough = DateSerial(M,D,Y)
End If
End Function







Jeff Boyce said:
I'm not clear whether you wish to control the display of a date (if so,
other folks have already discussed this) or wish to control what date is
used.

If the latter, perhaps the DateSerial() function could help.

Regards

Jeff Boyce
Microsoft Office/Access MVP

Signe said:
I built a database to track membership in our Club. On the form that I
record payment of dues I manually change the default value the 1st week of
January for the field labeled 'PdThrough' e.g. #12/31/2008#.

I want to hard code the PdThrough date to read m/d/yyyy. The year the
receipt was written is always the membership year. I looked at using the
Date Part function but I do not know how to pick up the month and day. I
would appreciate your help.

=Date Part("yyyy"(PymtDate]) Date Receipt is written: PymtDate (date
of
receipt)
 
D

Douglas J. Steele

DateSerial expects the parameters in year, month, day order, not month, day,
year.

Far simpler than what you have would be:

Private Sub PdThrough_Enter()

Me.PdThrough = DateSerial(Year([PymtDate], 12, 31)

End Sub

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Signe said:
I used the following code using the Date Serial. Based on the date of the
receipt (5/1/2008) the PdThrough date should have been 12/31/2008. but Pd
Through date was 12/29/2019. The month and day remain constant only the
year
changes.

Private Sub PdThrough_Enter()
Dim D as Integer, M as Integer, Y as Integer

If IsNull (PymtDate) Then
PdThrough = Null
Else
M = 12
D = 31
Y = DatePart("yyyy",[PymtDate])
PdThrough = DateSerial(M,D,Y)
End If
End Function







Jeff Boyce said:
I'm not clear whether you wish to control the display of a date (if so,
other folks have already discussed this) or wish to control what date is
used.

If the latter, perhaps the DateSerial() function could help.

Regards

Jeff Boyce
Microsoft Office/Access MVP

Signe said:
I built a database to track membership in our Club. On the form that I
record payment of dues I manually change the default value the 1st week
of
January for the field labeled 'PdThrough' e.g. #12/31/2008#.

I want to hard code the PdThrough date to read m/d/yyyy. The year the
receipt was written is always the membership year. I looked at using
the
Date Part function but I do not know how to pick up the month and day.
I
would appreciate your help.

=Date Part("yyyy"(PymtDate]) Date Receipt is written: PymtDate
(date
of
receipt)
 
S

Signe

Thank you very much - your coding is much simpler. After researching
further, I had figured out about the year, month, day format. After I made
the change to the coding the results were what I wanted.

Douglas J. Steele said:
DateSerial expects the parameters in year, month, day order, not month, day,
year.

Far simpler than what you have would be:

Private Sub PdThrough_Enter()

Me.PdThrough = DateSerial(Year([PymtDate], 12, 31)

End Sub

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Signe said:
I used the following code using the Date Serial. Based on the date of the
receipt (5/1/2008) the PdThrough date should have been 12/31/2008. but Pd
Through date was 12/29/2019. The month and day remain constant only the
year
changes.

Private Sub PdThrough_Enter()
Dim D as Integer, M as Integer, Y as Integer

If IsNull (PymtDate) Then
PdThrough = Null
Else
M = 12
D = 31
Y = DatePart("yyyy",[PymtDate])
PdThrough = DateSerial(M,D,Y)
End If
End Function







Jeff Boyce said:
I'm not clear whether you wish to control the display of a date (if so,
other folks have already discussed this) or wish to control what date is
used.

If the latter, perhaps the DateSerial() function could help.

Regards

Jeff Boyce
Microsoft Office/Access MVP

I built a database to track membership in our Club. On the form that I
record payment of dues I manually change the default value the 1st week
of
January for the field labeled 'PdThrough' e.g. #12/31/2008#.

I want to hard code the PdThrough date to read m/d/yyyy. The year the
receipt was written is always the membership year. I looked at using
the
Date Part function but I do not know how to pick up the month and day.
I
would appreciate your help.

=Date Part("yyyy"(PymtDate]) Date Receipt is written: PymtDate
(date
of
receipt)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top