Results 1 to 8 of 8

Thread: help on dao validation error binding.

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    13

    help on dao validation error binding.

    this code requires a class which binds all the error msg. i got this code without the module and i have got no idea on how to make the class. here is the code.

    Private Utility As New clsUtility
    Private mblnValidationFailed As Boolean

    Private Sub datEmployees_Validate(Action As Integer, Save As Integer)
    Dim strMsg As String
    Dim enumMsgResult As VbMsgBoxResult
    If Save = True Or Action = vbDataActionUpdate _
    Or Action = vbDataActionUnload Then
    strMsg = ""
    If txtEmpLastName.Text = "" Then
    Utility.AddToMsg strMsg, _
    "You must enter a last name."
    txtEmpLastName.SetFocus
    End If
    If txtEmpFirstName.Text = "" Then
    Utility.AddToMsg strMsg, _
    "You must enter a first name."
    txtEmpFirstName.SetFocus
    End If
    If Not IsDate(txtBirthDate.Text) Then
    Utility.AddToMsg strMsg, _
    "You must enter a birth date."
    txtBirthDate.SetFocus
    Else
    If CDate(txtBirthDate.Text) >= Date Then
    Utility.AddToMsg strMsg, _
    "Birth date must be in the past."
    txtBirthDate.SetFocus
    End If
    End If
    If strMsg <> "" Then
    ` We have something in the variable strMsg, which
    ` means that an error has occurred. Display the
    ` message. The focus is in the last text box where
    ` an error was found
    enumMsgResult = MsgBox(strMsg, _
    vbExclamation + vbOKCancel +
    vbDefaultButton1)
    If enumMsgResult = vbCancel Then
    ` Restore the data to previous values using the
    ` data control
    datEmployees.UpdateControls
    ` Allow form unload.
    mblnValidationFailed = False
    Else
    ` Cancel the Validate event
    Action = vbDataActionCancel
    ` Deny form unload until fields are corrected
    mblnValidationFailed = True
    End If
    Else
    mblnValidationFailed = False
    End If
    End If
    End Sub

    can you tell me how to make the class?
    thank you very much.

  2. #2
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160
    sorry but i don't know the answer to your question because I couldn't understand your question, anyway for better result for answering I would recommend to use TAB and Enter key in your code so its more categorized and easy to read, specially when it gets a bit long

    S. Mohammad Najafi

    PS : reffering to you last question , I consider you mean how to add class module which you can do it by click on PROJECT menu and click on ADD CLASS MODULE and you may probably paste it there...

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    13
    sorry. ill try to explain it.

    this program is for DAO database validation.
    when a field is empty, a msg box appears to notify the user that the field is empty amd that he should fill it. when there are two or more fields are empty, all of the msgs are binded by a class module (i think) in only one msg box. i dont know how to bind all these msgs to one msg box. thats where i need my help.

    i hope you get what i mean.
    i really need help man.

  4. #4
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160
    you can add this code to your event, give it a try and tell me if it works or not.

    Hope it helps
    S. Mohammad Najafi

    If txtEmpLastName.Text = "" Then
    strMsg = "- You must enter last name" & Chr(13)
    txtEmpLastName.SetFocus
    End If

    If txtEmpFirstName.Text = "" Then
    strMsg = "- You must enter First Name." & Chr(13)
    txtEmpFirstName.SetFocus
    Exit Sub
    End If

    If IsDate(txtBirthDate) = False Then
    MsgBox = "- You must enter Valid Date." & Chr(13)
    txtBirthDate.SetFocus
    Exit Sub
    End If

    If CDate(txtBirthDate) >= Date Then
    strMsg = "- Birth date must be in the past." & Chr(13)
    txtbirtdate.SetFocus
    End If

    If strMsg <> "" Then
    enumMsgResult = MsgBox(strMsg, vbExclamation + vbOKCancel + vbDefaultButton1)
    End If

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    13
    thanks for the help man but it doesnt work. i believe it requires a class to bind the msgs.

    do you know how to make the class?

  6. #6
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160
    Sorry I forgot to add something , try it again

    [vB code]
    If txtEmpLastName.Text = "" Then
    strMsg = "- You must enter last name" & Chr(13)
    txtEmpLastName.SetFocus
    End If

    If txtEmpFirstName.Text = "" Then
    strMsg = "- You must enter First Name." & Chr(13) & strMsg
    txtEmpFirstName.SetFocus
    End If

    If IsDate(txtBirthDate) = False Then
    MsgBox = "- You must enter Valid Date." & Chr(13) & strMsg
    txtBirthDate.SetFocus
    End If

    If CDate(txtBirthDate) >= Date Then
    strMsg = "- Birth date must be in the past." & Chr(13) & strMsg
    txtbirtdate.SetFocus
    End If

    If strMsg <> "" Then
    enumMsgResult = MsgBox(strMsg, vbExclamation + vbOKCancel + vbDefaultButton1)
    End If
    [/vB code]

  7. #7

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    13
    oh my it worked man! thanks a lot man. i really appreciate your help. im very thankful!

    thank you!

  8. #8
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160
    you're most welcome
    S. Mohammad Najafi

Posting Permissions

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



Click Here to Expand Forum to Full Width