Text Box Date Query

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

--
If I have 2 text boxes on my form
[tbStartDate1] & [tbEndDate1]
If I create a Command button on that form,What code would I need to the
first day of the current month in tbStartdate1 and the last day of the
current Month in tbEndDate1
thanks for any Help......Bob
 
Bob,


tbStartDate1=DateSerial(Year(Date),Month(Date),1)

tbEndDate1=IIf(month(date)=12,31, DateSerial(Year(Date),Month(Date)+1,1)-1)

Regards
Jacob
 
Oops

tbEndDate1=IIf(Month(Date)=12,DateSerial(Year(Date),Month(Date),31),DateSerial(Year(Date),Month(Date)+1,1)-1)


JK said:
Bob,


tbStartDate1=DateSerial(Year(Date),Month(Date),1)

tbEndDate1=IIf(month(date)=12,31,
DateSerial(Year(Date),Month(Date)+1,1)-1)

Regards
Jacob


Bob said:
--
If I have 2 text boxes on my form
[tbStartDate1] & [tbEndDate1]
If I create a Command button on that form,What code would I need to the
first day of the current month in tbStartdate1 and the last day of the
current Month in tbEndDate1
thanks for any Help......Bob
 
If I have 2 text boxes on my form
[tbStartDate1] & [tbEndDate1]
If I create a Command button on that form,What code would I need to the
first day of the current month in tbStartdate1 and the last day of the
current Month in tbEndDate1
thanks for any Help......Bob

Private Sub cmdFillDate_Click()
Me!tbStartDate1 = DateSerial(Year(Date()), Month(Date()), 1)
Me!tbEndDate1 = DateSerial(Year(Date()), Month(Date()) + 1, 0)
End Sub

Or you can simply set the DefaultValue property of each textbox to the
corresponding DateSerial expression.

John W. Vinson[MVP]
 
Oops

tbEndDate1=IIf(Month(Date)=12,DateSerial(Year(Date),Month(Date),31),DateSerial(Year(Date),Month(Date)+1,1)-1)

Not needed. DateSerial is quite clever enough to recognise that the
thirteenth month of this year is actually the first month of next
year, and that the zeroth of next month is the last day of this month.


John W. Vinson[MVP]
 
Hi John,

Thanks for your feedback.

I fully agree. I had not realized it until I read your reply to Bob (and ran
some tests). Having "graduated" in the old DOS/Fortran/dBase days, I still
tend to eliminate possible errors, whether needed be or not.

This old dog can still learn a few new tricks.

Regards and a happy new year.
Jacob
 
John I thought the Default value was a great idea and tried it but I could
not get the text boxes to open with any date I entered this in the first
text box/default values :DateSerial(Year(Date()), Month(Date()), 1)
Thanks bob

John Vinson said:
If I have 2 text boxes on my form
[tbStartDate1] & [tbEndDate1]
If I create a Command button on that form,What code would I need to the
first day of the current month in tbStartdate1 and the last day of the
current Month in tbEndDate1
thanks for any Help......Bob

Private Sub cmdFillDate_Click()
Me!tbStartDate1 = DateSerial(Year(Date()), Month(Date()), 1)
Me!tbEndDate1 = DateSerial(Year(Date()), Month(Date()) + 1, 0)
End Sub

Or you can simply set the DefaultValue property of each textbox to the
corresponding DateSerial expression.

John W. Vinson[MVP]
 
No matter went with the button and that worked fine thanks for all your
help..Bob

Bob said:
John I thought the Default value was a great idea and tried it but I could
not get the text boxes to open with any date I entered this in the first
text box/default values :DateSerial(Year(Date()), Month(Date()), 1)
Thanks bob

John Vinson said:
If I have 2 text boxes on my form
[tbStartDate1] & [tbEndDate1]
If I create a Command button on that form,What code would I need to the
first day of the current month in tbStartdate1 and the last day of the
current Month in tbEndDate1
thanks for any Help......Bob

Private Sub cmdFillDate_Click()
Me!tbStartDate1 = DateSerial(Year(Date()), Month(Date()), 1)
Me!tbEndDate1 = DateSerial(Year(Date()), Month(Date()) + 1, 0)
End Sub

Or you can simply set the DefaultValue property of each textbox to the
corresponding DateSerial expression.

John W. Vinson[MVP]
 

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

Similar Threads


Back
Top