How can I enter this default date? (1 Viewer)

acepayne

Registered User.
Local time
Today, 10:12
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!
 

cargobay 69

Registered User.
Local time
Today, 10:12
Joined
May 1, 2001
Messages
25
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

Registered User.
Local time
Today, 10:12
Joined
Jul 26, 2001
Messages
44
Thanks man! Works great.

Appreciate it!
 

John S

Registered User.
Local time
Today, 10:12
Joined
Jun 30, 2000
Messages
18
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

Dim Person
Local time
Today, 10:12
Joined
Sep 1, 2000
Messages
1,396
Some thing like:

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

Users who are viewing this thread

Top Bottom