Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: need a sniplet of vb code please!

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    88
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I need some code to check that a field is filled out before allowing the user to submit on a custom userform. Basically I have a date field in the custom form and I need to make SURE the user fills in that field but proceeding. So I need code to check the date field for a valid value when they click "ok". If there is not a value I need it to pop up the user an error saying something like "Date Field must be completed" Please Help, Thanks...

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sydney, Australia
    Posts
    2,940
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    Keith,

    This code assumes that your textbox is called txtDate and your OK button is called cmdOK. Hope it helps,

    D

    Code:
    Private Sub cmdOK_Click()
    If Not IsDate(txtDate.Text) Then
        MsgBox "Date field is not a valid date.", vbExclamation, "Error"
        Me.txtDate.Text = ""
        Me.txtDate.SetFocus
        Exit Sub
    ElseIf txtDate.Text = "" Then
        MsgBox "Date field must be completed.", vbExclamation, "Error"
        Me.txtDate.Text = ""
        Me.txtDate.SetFocus
        Exit Sub
    End If
    
    'Rest of your code
    MsgBox "Congratulations!  You entered a valid date"
    
    End Sub

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Posts
    88
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Works like a charm! Thanks tremendously..

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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