Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Code For Date Accepts Text

Can someone tell me what is wrong here? Am asking the user to input a date
in the mm/dd/yy format. It works ok except that it accepts any text string
that is entered (it rejects something like January 3, 2006 though).
Obviously, I do not want it to accept text, and cannot figure out how to fix
this. Any help would be appreciated....am sure it is something simple.

Sub SWStartDate()
Dim UserEntry As String
Dim Msg As String
Msg = "Enter the contract start date, in mm/dd/yy format; then click on 'OK'."
Do
UserEntry = InputBox(Msg)
If UserEntry = "" Then
MsgBox ("You must enter a response; please try again.")
End If
If UserEntry < "" Then
If UserEntry = Format(UserEntry, "mm/dd/yy") Then
Exit Do
End If
If UserEntry < Format(UserEntry, "mm/dd/yy") Then
Msg = "Invalid entry; please enter a date in the mm/dd/yy
format."
End If
End If
Msg = "Invalid entry; please enter a date in the mm/dd/yy format."
Loop
Worksheets("Software Inventory").Range("C5").Value = UserEntry
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Code For Date Accepts Text

Hi Paige

Use the VBA IsDate function to test if Msg is a date
See VBA help for IsDate

--
Regards Ron De Bruin
http://www.rondebruin.nl



"Paige" wrote in message ...
Can someone tell me what is wrong here? Am asking the user to input a date
in the mm/dd/yy format. It works ok except that it accepts any text string
that is entered (it rejects something like January 3, 2006 though).
Obviously, I do not want it to accept text, and cannot figure out how to fix
this. Any help would be appreciated....am sure it is something simple.

Sub SWStartDate()
Dim UserEntry As String
Dim Msg As String
Msg = "Enter the contract start date, in mm/dd/yy format; then click on 'OK'."
Do
UserEntry = InputBox(Msg)
If UserEntry = "" Then
MsgBox ("You must enter a response; please try again.")
End If
If UserEntry < "" Then
If UserEntry = Format(UserEntry, "mm/dd/yy") Then
Exit Do
End If
If UserEntry < Format(UserEntry, "mm/dd/yy") Then
Msg = "Invalid entry; please enter a date in the mm/dd/yy
format."
End If
End If
Msg = "Invalid entry; please enter a date in the mm/dd/yy format."
Loop
Worksheets("Software Inventory").Range("C5").Value = UserEntry
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 270
Default Code For Date Accepts Text

Works like a charm! Thanks so much Ron!

"Ron de Bruin" wrote:

Hi Paige

Use the VBA IsDate function to test if Msg is a date
See VBA help for IsDate

--
Regards Ron De Bruin
http://www.rondebruin.nl



"Paige" wrote in message ...
Can someone tell me what is wrong here? Am asking the user to input a date
in the mm/dd/yy format. It works ok except that it accepts any text string
that is entered (it rejects something like January 3, 2006 though).
Obviously, I do not want it to accept text, and cannot figure out how to fix
this. Any help would be appreciated....am sure it is something simple.

Sub SWStartDate()
Dim UserEntry As String
Dim Msg As String
Msg = "Enter the contract start date, in mm/dd/yy format; then click on 'OK'."
Do
UserEntry = InputBox(Msg)
If UserEntry = "" Then
MsgBox ("You must enter a response; please try again.")
End If
If UserEntry < "" Then
If UserEntry = Format(UserEntry, "mm/dd/yy") Then
Exit Do
End If
If UserEntry < Format(UserEntry, "mm/dd/yy") Then
Msg = "Invalid entry; please enter a date in the mm/dd/yy
format."
End If
End If
Msg = "Invalid entry; please enter a date in the mm/dd/yy format."
Loop
Worksheets("Software Inventory").Range("C5").Value = UserEntry
End Sub




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create list validation from code without the text being converted into date format? EG[_3_] Excel Programming 2 November 24th 05 10:16 AM
Textbox accepts alpha only LeLi Excel Programming 2 August 2nd 05 08:03 AM
TextBox that only accepts integers? Claud Balls Excel Programming 2 January 4th 05 10:57 PM
code to convert date from TEXT format (03-02) to DATE format (200203) Gauthier[_2_] Excel Programming 0 September 22nd 04 03:26 PM
Date problem from code to text box to spreadsheet Joe 90[_2_] Excel Programming 2 October 20th 03 11:18 PM


All times are GMT +1. The time now is 05:49 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"