PC Review


Reply
Thread Tools Rate Thread

Check Input for Valid Month

 
 
=?Utf-8?B?U0xXNjEy?=
Guest
Posts: n/a
 
      24th Sep 2007
Hello,
I am looking for a code that will automatically check an input box to make
sure the values entered are accurate. I don't know how to check to make sure
the month entered is the full name (and spelled correctly), and if not an
error message comes up to prompt for a correct entry. Thanks in advance!


Sub testdate()
Dim MyDate
Dim Message As String, Title As String
Dim current_date As String

MyDate = Format(Date, "mmmm yyy")

Message = "ENTER FULL MONTH AND YEAR FOR REPORT:"
Title = "Enter Date"
Default = MyDate
current_date = InputBox(Message, Title, Default)

Application.ScreenUpdating = False

With Sheets("Summary").Range("B2")
.NumberFormat = "mmmm yyy"
.Value = current_date
End With
Application.ScreenUpdating = True

End Sub
 
Reply With Quote
 
 
 
 
=?Utf-8?B?U0xXNjEy?=
Guest
Posts: n/a
 
      24th Sep 2007
Sorry, I just checked my code again (should have checked after editing and
before posting), and it is giving me a strange default year - "07267" instead
of 2007.

I also added "Default as String" because I forgot that too. SO my issues
now are DEFAULT YEAR coming out strange and needing to check validity for
MONTH.

Thanks!


"SLW612" wrote:

> Hello,
> I am looking for a code that will automatically check an input box to make
> sure the values entered are accurate. I don't know how to check to make sure
> the month entered is the full name (and spelled correctly), and if not an
> error message comes up to prompt for a correct entry. Thanks in advance!
>
>
> Sub testdate()
> Dim MyDate
> Dim Message As String, Title As String
> Dim current_date As String
>
> MyDate = Format(Date, "mmmm yyy")
>
> Message = "ENTER FULL MONTH AND YEAR FOR REPORT:"
> Title = "Enter Date"
> Default = MyDate
> current_date = InputBox(Message, Title, Default)
>
> Application.ScreenUpdating = False
>
> With Sheets("Summary").Range("B2")
> .NumberFormat = "mmmm yyy"
> .Value = current_date
> End With
> Application.ScreenUpdating = True
>
> End Sub

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      24th Sep 2007
Sub testdate()
Dim MyDate
Dim Message As String, Title As String
Dim current_date As String
Dim Default
Dim FirstDay As Date

MyDate = Format(Date, "mmmm yyyy")

Message = "ENTER FULL MONTH AND YEAR FOR REPORT:"
Title = "Enter Date"
Default = MyDate
current_date = InputBox(Message, Title, Default)
On Error Resume Next
FirstDay = DateValue("01 " & current_date)
On Error GoTo 0
If FirstDay <> 0 Then
Application.ScreenUpdating = False

With Sheets("Summary").Range("B2")
.NumberFormat = "mmmm yyy"
.Value = current_date
End With
Application.ScreenUpdating = True
Else

MsgBox "Invalid date"
End If

End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"SLW612" <(E-Mail Removed)> wrote in message
news:B40C3A36-5E49-4C01-8F8F-(E-Mail Removed)...
> Hello,
> I am looking for a code that will automatically check an input box to make
> sure the values entered are accurate. I don't know how to check to make
> sure
> the month entered is the full name (and spelled correctly), and if not an
> error message comes up to prompt for a correct entry. Thanks in advance!
>
>
> Sub testdate()
> Dim MyDate
> Dim Message As String, Title As String
> Dim current_date As String
>
> MyDate = Format(Date, "mmmm yyy")
>
> Message = "ENTER FULL MONTH AND YEAR FOR REPORT:"
> Title = "Enter Date"
> Default = MyDate
> current_date = InputBox(Message, Title, Default)
>
> Application.ScreenUpdating = False
>
> With Sheets("Summary").Range("B2")
> .NumberFormat = "mmmm yyy"
> .Value = current_date
> End With
> Application.ScreenUpdating = True
>
> End Sub



 
Reply With Quote
 
=?Utf-8?B?U0xXNjEy?=
Guest
Posts: n/a
 
      24th Sep 2007
Thanks for the quick reply Bob ...
But how do I get it to loop if the date entered is, in fact, invalid?


"Bob Phillips" wrote:

> Sub testdate()
> Dim MyDate
> Dim Message As String, Title As String
> Dim current_date As String
> Dim Default
> Dim FirstDay As Date
>
> MyDate = Format(Date, "mmmm yyyy")
>
> Message = "ENTER FULL MONTH AND YEAR FOR REPORT:"
> Title = "Enter Date"
> Default = MyDate
> current_date = InputBox(Message, Title, Default)
> On Error Resume Next
> FirstDay = DateValue("01 " & current_date)
> On Error GoTo 0
> If FirstDay <> 0 Then
> Application.ScreenUpdating = False
>
> With Sheets("Summary").Range("B2")
> .NumberFormat = "mmmm yyy"
> .Value = current_date
> End With
> Application.ScreenUpdating = True
> Else
>
> MsgBox "Invalid date"
> End If
>
> End Sub
>
>
> --
> ---
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
>
>
> "SLW612" <(E-Mail Removed)> wrote in message
> news:B40C3A36-5E49-4C01-8F8F-(E-Mail Removed)...
> > Hello,
> > I am looking for a code that will automatically check an input box to make
> > sure the values entered are accurate. I don't know how to check to make
> > sure
> > the month entered is the full name (and spelled correctly), and if not an
> > error message comes up to prompt for a correct entry. Thanks in advance!
> >
> >
> > Sub testdate()
> > Dim MyDate
> > Dim Message As String, Title As String
> > Dim current_date As String
> >
> > MyDate = Format(Date, "mmmm yyy")
> >
> > Message = "ENTER FULL MONTH AND YEAR FOR REPORT:"
> > Title = "Enter Date"
> > Default = MyDate
> > current_date = InputBox(Message, Title, Default)
> >
> > Application.ScreenUpdating = False
> >
> > With Sheets("Summary").Range("B2")
> > .NumberFormat = "mmmm yyy"
> > .Value = current_date
> > End With
> > Application.ScreenUpdating = True
> >
> > End Sub

>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      21st Oct 2007
Sub testdate()
Dim MyDate
Dim Message As String, Title As String
Dim current_date As String
Dim Default
Dim FirstDay As Date

MyDate = Format(Date, "mmmm yyyy")

Do
Message = "ENTER FULL MONTH AND YEAR FOR REPORT:"
Title = "Enter Date"
Default = MyDate
current_date = InputBox(Message, Title, Default)
If current_date = "" Then
Exit Do
Else
On Error Resume Next
FirstDay = DateValue("01 " & current_date)
On Error GoTo 0
If FirstDay <> 0 Then
Application.ScreenUpdating = False

With Sheets("Summary").Range("B2")
.NumberFormat = "mmmm yyy"
.Value = current_date
End With
current_date = ""
Application.ScreenUpdating = True
Else

MsgBox "Invalid date"
End If
End If
Loop Until current_date = ""
End Sub

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"SLW612" <(E-Mail Removed)> wrote in message
news:88266DC8-5A25-4EC4-BC9D-(E-Mail Removed)...
> Thanks for the quick reply Bob ...
> But how do I get it to loop if the date entered is, in fact, invalid?
>
>
> "Bob Phillips" wrote:
>
>> Sub testdate()
>> Dim MyDate
>> Dim Message As String, Title As String
>> Dim current_date As String
>> Dim Default
>> Dim FirstDay As Date
>>
>> MyDate = Format(Date, "mmmm yyyy")
>>
>> Message = "ENTER FULL MONTH AND YEAR FOR REPORT:"
>> Title = "Enter Date"
>> Default = MyDate
>> current_date = InputBox(Message, Title, Default)
>> On Error Resume Next
>> FirstDay = DateValue("01 " & current_date)
>> On Error GoTo 0
>> If FirstDay <> 0 Then
>> Application.ScreenUpdating = False
>>
>> With Sheets("Summary").Range("B2")
>> .NumberFormat = "mmmm yyy"
>> .Value = current_date
>> End With
>> Application.ScreenUpdating = True
>> Else
>>
>> MsgBox "Invalid date"
>> End If
>>
>> End Sub
>>
>>
>> --
>> ---
>> HTH
>>
>> Bob
>>
>> (there's no email, no snail mail, but somewhere should be gmail in my
>> addy)
>>
>>
>>
>> "SLW612" <(E-Mail Removed)> wrote in message
>> news:B40C3A36-5E49-4C01-8F8F-(E-Mail Removed)...
>> > Hello,
>> > I am looking for a code that will automatically check an input box to
>> > make
>> > sure the values entered are accurate. I don't know how to check to make
>> > sure
>> > the month entered is the full name (and spelled correctly), and if not
>> > an
>> > error message comes up to prompt for a correct entry. Thanks in
>> > advance!
>> >
>> >
>> > Sub testdate()
>> > Dim MyDate
>> > Dim Message As String, Title As String
>> > Dim current_date As String
>> >
>> > MyDate = Format(Date, "mmmm yyy")
>> >
>> > Message = "ENTER FULL MONTH AND YEAR FOR REPORT:"
>> > Title = "Enter Date"
>> > Default = MyDate
>> > current_date = InputBox(Message, Title, Default)
>> >
>> > Application.ScreenUpdating = False
>> >
>> > With Sheets("Summary").Range("B2")
>> > .NumberFormat = "mmmm yyy"
>> > .Value = current_date
>> > End With
>> > Application.ScreenUpdating = True
>> >
>> > End Sub

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check Date, Include dates from rest of month and all of next month MSchmidty2 Microsoft Excel Programming 4 28th Jul 2009 05:08 PM
Check for valid date on input box =?Utf-8?B?UGVuZHJhZ29u?= Microsoft Access VBA Modules 2 28th Aug 2007 04:06 PM
convert month-year to valid date ragtopcaddy via AccessMonster.com Microsoft Access VBA Modules 3 6th Jun 2006 04:15 PM
Waiting for a valid input serge Microsoft Excel Programming 1 16th Jan 2004 02:47 PM
Input Valid =?Utf-8?B?Vm8gRHVvbmcgSG9h?= Microsoft Access 1 18th Nov 2003 12:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:34 AM.