Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Posts
    11

    Unanswered: Please Help with Code

    Private Sub txtDate_BeforeUpdate(Cancel As Integer)

    If IsDate(txtDate) Then
    MsgBox "Valid Date entered" 'Msg1
    Else
    MsgBox "Invalid Date entered!" 'Msg2
    End If

    End Sub

    The code above works OK for: a valid txtDate (Msg1 is displayed),
    and an empty txtDate (Msg2 is displayed). However, if I entered "ABC" into the text box, I got an Access generic error message instead of the expected Msg2. Please help me with the date validation.

  2. #2
    Join Date
    Oct 2002
    Location
    Greensboro, NC
    Posts
    50

    Re: Please Help with Code

    Originally posted by diensatthan
    Private Sub txtDate_BeforeUpdate(Cancel As Integer)

    If IsDate(txtDate) Then
    MsgBox "Valid Date entered" 'Msg1
    Else
    MsgBox "Invalid Date entered!" 'Msg2
    End If

    End Sub

    The code above works OK for: a valid txtDate (Msg1 is displayed),
    and an empty txtDate (Msg2 is displayed). However, if I entered "ABC" into the text box, I got an Access generic error message instead of the expected Msg2. Please help me with the date validation.
    What is the error message you're getting?

  3. #3
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    did you try an input mask on the text-box?
    "ABC" goes away.

    izy

  4. #4
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    The field will be a date/time I guess (as Izy said).

    Make the code:

    Private Sub txtDate_BeforeUpdate(Cancel As Integer)

    docmd.setwarnings false
    If IsDate(txtDate) Then
    MsgBox "Valid Date entered" 'Msg1
    Else
    MsgBox "Invalid Date entered!" 'Msg2
    End If
    docmd.setwarnings true
    End Sub

    Make sure you make the setwarnings true at the end or the world could come to an end or something..
    J.

Posting Permissions

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