View Full Version : How can I enter this default date?


acepayne
07-26-2001, 08:52 AM
Hello ,
I would like to set a textBox on a form to a default date of the 1st of the next month.

Sooo, if it is July 26, 2001 today, and I open the form up, I would the like the text box to display August 1, 2001 (actually, it would be in the short date format: 26-Jul-2001 here).

Any suggestions?

Thanks!

cargobay 69
07-26-2001, 03:38 PM
Here, try this;
Create a module in your project and insert the following code:

'--------------------------------------------
Public Function FirstOfNextMonth() As Variant

Dim intDay As Integer
Dim intMonth As Integer
Dim intYear As Integer

Dim varNextMonth As Variant

intDay = 1
intMonth = Format(Date, "m") + 1
intYear = Format(Date, "yy")

varNextMonth = intMonth & "/" & intDay & "/" & intYear

FirstOfNextMonth = varNextMonth

End Function
'--------------------------------------------

Save the module and name it whatever you want. Then on your form, set your text box's default value to:

=Format(FirstOfNextMonth(),"ddddd")

You can change the format to whatever suits you.
I hope it all works for you.

Darrin@CB69

acepayne
07-27-2001, 05:58 AM
Thanks man! Works great.

Appreciate it!

John S
07-27-2001, 07:55 AM
Looks to me like you'll need to add a bit of code to handle dates in December - to ensure that the 'year' part of the date increments properly.

John

Fornatian
07-27-2001, 09:44 AM
Some thing like:

intYear = Iif(Month(Date)=12,Format(Date, "yy")+1,Format(Date, "yy"))

acepayne
07-27-2001, 11:37 AM
Good point!!!

Thanks a million!

cargobay 69
07-27-2001, 11:42 AM
Good call John, I forgot about that. Thanks.

Darrin@CB69