How can I enter this default date?

acepayne

Registered User.
Local time
Today, 00:33
Joined
Jul 26, 2001
Messages
44
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!
 
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
 
Thanks man! Works great.

Appreciate it!
 
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
 
Some thing like:

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

Users who are viewing this thread

Back
Top Bottom