Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert First day and last day of Current Month

Status
Not open for further replies.

barra47

Programmer
Dec 25, 2002
86
AU
I have 2 fields in a form
start date
End date
when the form is open i wish to have those fields automaticaly populated with the first and last day of the current month
Please - How do i get this result.

Thanks in advance

 
In the Load event procedure of the form:
Me![start date] = DateSerial(Year(Date), Month(Date), 1)
Me![End date] = DateSerial(Year(Date), 1 + Month(Date), 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Good code, I hadn't seen that before. One thing I like to do with this kind of entry is put two buttons above the boxes to change months next and previous. The users love it.
 
Just what i was looking for thank you very much for your promt reply and answer
 
Hi stix4t2
that sounds interesting
I would like to know what your code is behind these buttons
I think I can use that also

Thanks
 
Have a look at the DateAdd function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV

I wrote the following on 2 buttons for next month and previous month


Next
Private Sub Command122_Click()
Me!BeginningDate = DateAdd("m", -1, [BeginningDate])
Me!EndingDate = DateAdd("m", -1, [EndingDate])
End Sub

Previous
Private Sub Command122_Click()
Me!BeginningDate = DateAdd("m", -1, [BeginningDate])
Me!EndingDate = DateAdd("m", -1, [EndingDate])
End Sub

If I start with 1/1/2006 and 31/1/2006

and click next it changes to
1/2/2006 and 28/2/2006
as one would expect
but when i click for next month again i get the following
1/3/2006 and 28/2/2006 not 31/3/2006
and each month remains at 28/4/2006 etc


???
 
So, play again with the DateSerial function:
Me!EndingDate = DateSerial(Year(Me!EndingDate), 2 + Month(Me!EndingDate), 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top