|
-
Sep 26th, 2003, 09:57 AM
#1
Thread Starter
New Member
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.
-
Sep 27th, 2003, 02:50 AM
#2
Addicted Member
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...
-
Sep 27th, 2003, 03:40 AM
#3
Thread Starter
New Member
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.
-
Sep 27th, 2003, 04:31 AM
#4
Addicted Member
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
-
Sep 27th, 2003, 04:54 AM
#5
Thread Starter
New Member
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?
-
Sep 27th, 2003, 05:02 AM
#6
Addicted Member
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]
-
Sep 27th, 2003, 09:55 AM
#7
Thread Starter
New Member
oh my it worked man! thanks a lot man. i really appreciate your help. im very thankful!
thank you!
-
Sep 27th, 2003, 10:23 AM
#8
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|