Adding month end date

A

Alex Martinez

Hi,

I am using Access 2002 and I have two text boxes in my form that the user
populates. The first text box called assigned date the user will put a date
for example September 5th 2005 and the second text box call month end. What
I want is when the user put a date in the assigned text box I want the month
end to become September 30th 2005. If the use inputes October 1st 2005 the
month end box will automatically populates to October 31, 2005. Any tips
will be appreicated. Thank you.
 
S

Sandro

Alex Martinez said:
Hi,

I am using Access 2002 and I have two text boxes in my form that the user
populates. The first text box called assigned date the user will put a date
for example September 5th 2005 and the second text box call month end. What
I want is when the user put a date in the assigned text box I want the month
end to become September 30th 2005. If the use inputes October 1st 2005 the
month end box will automatically populates to October 31, 2005. Any tips
will be appreicated. Thank you.
Hi Alex,

try in this way. In the after update event of your text box where you put
the date ( September 5th 2005 ) write this code :

me!yourEndMonthDate=DateSerial(Year(Format(YourTextBox, "yyyy/mm/mm")),
Month(Format(YourTextBox, "yyyy/mm/dd")) + 1, 0)

YourTextBox is the textbox where you write September 5th 2005 and
yourEndMonthDate is the textbox where you want tha date of the end of month.

Ciao, Sandro
 
D

Douglas J. Steele

Sandro said:
Hi Alex,

try in this way. In the after update event of your text box where you put
the date ( September 5th 2005 ) write this code :

me!yourEndMonthDate=DateSerial(Year(Format(YourTextBox, "yyyy/mm/mm")),
Month(Format(YourTextBox, "yyyy/mm/dd")) + 1, 0)

YourTextBox is the textbox where you write September 5th 2005 and
yourEndMonthDate is the textbox where you want tha date of the end of
month.

There's no reason to use the Format function on the data in the text boxes.
If anything, CDate would be more appropriate:

me!yourEndMonthDate=DateSerial(Year(CDate(YourTextBox)),
Month(CDate(YourTextBox)) + 1, 0)
 
S

Sandro

[cut]

hi Douglas,
There's no reason to use the Format function on the data in the text boxes.
If anything, CDate would be more appropriate:

me!yourEndMonthDate=DateSerial(Year(CDate(YourTextBox)),
Month(CDate(YourTextBox)) + 1, 0)

I'm writing from Italy... I don't know if in the other European State is the
same, but in Italy if we don't want to have problem with date we must format
the date in the Iso format international (8601) or in the american format.

That's why I posted that code. I think you know this our problem...

Ciao, Sandro
 
D

Douglas J. Steele

Sandro said:
[cut]

hi Douglas,
There's no reason to use the Format function on the data in the text boxes.
If anything, CDate would be more appropriate:

me!yourEndMonthDate=DateSerial(Year(CDate(YourTextBox)),
Month(CDate(YourTextBox)) + 1, 0)

I'm writing from Italy... I don't know if in the other European State is
the
same, but in Italy if we don't want to have problem with date we must
format
the date in the Iso format international (8601) or in the american format.

That's why I posted that code. I think you know this our problem...

I'm well aware of problems with internationalizing dates. What you're doing
is forcing data coercion a couple of times: you're expect the Format
function to transform the input into a string in a particular format (hoping
that a date was passed), then you're expecting the Year and Month functions
to convert that string into a date in order for them to work. Coercion is
seldom a good idea: it's far better that you control the conversion, rather
than leaving it to chance!

CDate is one of the few functions that respects regional date settings. If
CDate can't convert the input into a date (which is what the Year and Month
functions expect), then your Format statement isn't going to recognize the
input as being a date, so it's not going to work anyhow.
 

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