Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if date is 1st of the month

Status
Not open for further replies.

ali32uk

Technical User
Mar 31, 2011
22
GB
Hi All

I m hoping this is simple one.. I just want to check if the date entered is 1st of the month, if not display a msgbox for user to correct?

Appreciate your help

thank you

Ali
 
HI,

Give the user a year and month to select.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Here is one way you can check it, and if the date is NOT 1st of the month, you can [blue]make it [/blue]to be the 1st of the month:

Code:
Dim datDate As Date

datDate = Date

If Day(datDate) = 1 Then
    MsgBox "Bingo!"
Else
    MsgBox "It is NOT a 1st of the month"[blue]
    MsgBox "Date entered will be 1/" & Month(datDate) & "/" & Year(datDate)[/blue]
End If

But I would go with Skip's suggestion.

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
I ve tried the code, unfortunately it does nt work, even if I select 1st of month its still picks up the else function

Ali
 
The problem is [highlight #FCE94F]HERE[/highlight]
Code:
Dim datDate As Date

[highlight #FCE94F]datDate = Date[/highlight]

If Day(datDate) = 1 Then
    MsgBox "Bingo!"
Else
    MsgBox "It is NOT a 1st of the month"
    MsgBox "Date entered will be 1/" & Month(datDate) & "/" & Year(datDate)
End If

[highlight #FCE94F]Date[/highlight] is today's date!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Andrzejek's code is an example of detecting if a wrong date is entered, and illustrates how to build the correct date in the Else statement (effectively implementing Skip's solution). It is not, hoever, a code complete solution for your post. He's hoping that, having pointed you in the right direction, you might be able to take the remaining steps yourself.
 
Why give the user a chance to fail? Give the user the options that cannot fail.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Right on, strongm [thumbsup2]

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top