+ Reply to Thread
Results 1 to 2 of 2

Input Box Help - Validate Date Format

  1. #1
    Registered User
    Join Date
    07-18-2005
    Posts
    4

    Question Input Box Help - Validate Date Format

    need to code that will validate that the user has input the date (via InputBox) in the correct format. The user will be prompted to input the date in the format: Month (first three letters only) [space] Year (4-digit year), e.g., Jan 2005.

    I am having trouble validating the month format. Any suggestions would be greatly appreciated. I am sure this is basic VBA but I am feeling VBA-challenged today!

  2. #2
    Dave Peterson
    Guest

    Re: Input Box Help - Validate Date Format

    Maybe something like:

    Option Explicit
    Sub testme()

    Dim mCtr As Long
    Dim myStr As String
    Dim okDate As Boolean
    Dim FoundMonth As Boolean

    okDate = False

    Do
    myStr = InputBox(prompt:="enter date: mmm yyyy")

    If myStr = "" Then Exit Sub 'user hit cancel

    okDate = True
    If Len(myStr) <> 8 Then
    okDate = False
    ElseIf Mid(myStr, 4, 1) <> " " Then
    okDate = False
    ElseIf IsNumeric(Mid(myStr, 5, 4)) = False Then
    okDate = False
    Else
    FoundMonth = False
    For mCtr = 1 To 12
    If LCase(Left(myStr, 3)) _
    = LCase(Format(DateSerial(2005, mCtr, 1), "mmm")) Then
    FoundMonth = True
    Exit For
    End If
    Next mCtr
    If FoundMonth = False Then
    okDate = False
    End If
    End If

    If okDate = True Then Exit Do
    Loop

    End Sub

    Another option:

    You might want to take a look at Ron de Bruin's site for some tips/code/free
    calendar control:
    http://www.rondebruin.nl/calendar.htm


    Tbal wrote:
    >
    > need to code that will validate that the user has input the date (via
    > InputBox) in the correct format. The user will be prompted to input the
    > date in the format: Month (first three letters only) [space] Year
    > (4-digit year), e.g., Jan 2005.
    >
    > I am having trouble validating the month format. Any suggestions would
    > be greatly appreciated. I am sure this is basic VBA but I am feeling
    > VBA-challenged today!
    >
    > --
    > Tbal
    > ------------------------------------------------------------------------
    > Tbal's Profile: http://www.excelforum.com/member.php...o&userid=25317
    > View this thread: http://www.excelforum.com/showthread...hreadid=440421


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1