Auto Enabling of Command Button

S

SeRene

Hi, I need to diable a command button until the system
date of my computer reaches the last day of the month then
the command button will be enabled.

Is it possible to get this done?

I'm not very good at coding but my logic is...
--> Command0.Enabled = False on form load then use If..
Then..Else statement.

I will appreciate if some1 can kindly assist me on this!!
Thanks
 
N

Nikos Yannacopoulos

SeRene,

You're on the right track.
Not all months have the same number of days, so which is the last each
month? Well, it's the one right before the first of the next month! So the
trick is to check if tomorrow's day part of the date is 1:

On Form Open/Load:

Command0.Enabled = False
If Day(Date() +1) = 1 Then Command0.Enabled = True

HTH,
Nikos

Set the Enabled property of the command button
 
T

technolust

Copy and paste the following code into the Form_Load event:

Command0.Enabled = (DatePart("d", Date) _
= GetNumOfDaysInMonth(Date))

Next, copy and paste the following after the End Sub statement of the
Form_Load event:

Private Function GetNumOfDaysInMonth( _
ByVal dtDate As Date) As Integer
Dim dtBeginThisMonth As Date, dtBeginNextMonth As Date
Dim intMo1 As Integer

intMo1 = DatePart("m", dtDate)

dtBeginThisMonth = CDate(intMo1 _
& "/01/" & DatePart("yyyy", dtDate))

dtBeginNextMonth = DateAdd("m", 1, dtBeginThisMonth)

GetNumOfDaysInMonth = DateDiff("d", dtBeginThisMonth, _
dtBeginNextMonth)
End Function
 

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

Top