PDA

View Full Version : Solved: validate string of questions would like to stop processing between questions



Trevor
03-09-2008, 08:19 PM
I have a string of questions for data validation, each with a custom error message, I would like to stop the processing between questions. you can see by looking at my questions that there is "if vbok then goto endd:"
this only works for 1 question and the the command button will not work any more, but if I remove the "if vbok then goto endd:" then after clicking ok on an error message , the user is then presented with the next error message.
I have tried changeing from if len to just if <arg> = "" and the command button will not respond (I know thats strange becuse I have tons of IF statements throught my DB, here is my code of error messages:
If Len(Me.[To C/O] & vbNullString) = 0 Then MsgBox "To C/O is blank, if there isn't data for To C/O then type 'N/A'", vbInformation, _
"Data Required..."
' If vbOK Then GoTo Endd
If Len(Me.[To Address] & vbNullString) = 0 Then MsgBox "To Address is blank, you must enter an individual's Street address ", vbInformation, _
"Data Required..."
' If vbOK Then GoTo Endd
If Len(Me.[To Address Line 2] & vbNullString) = 0 Then MsgBox "To Address Lin 2 is blank, if there isn't data for To Address Line 2 then type 'N/A'", vbInformation, _
"Data Required..."
' If vbOK Then GoTo Endd
If Len(Me.[To Apt./Rm. #] & vbNullString) = 0 Then MsgBox "To Apt./Rm. # is blank, if there isn't data for To To Apt./Rm. # then type 'N/A'", vbInformation, _
"Data Required..."
' If vbOK Then GoTo Endd
If Len(Me.[To City] & vbNullString) = 0 Then MsgBox "To City is blank, you must enter an individual's City", vbInformation, _
"Data Required..."
' If vbOK Then GoTo Endd
If Len(Me.[To State] & vbNullString) = 0 Then MsgBox "To State is blank, you must enter an individual's State", vbInformation, _
"Data Required..."
' If vbOK Then GoTo Endd
If Len(Me.[To Zip Code] & vbNullString) = 0 Then MsgBox "To Zip Code is blank, you must enter an individual's Zip Code ", vbInformation, _
"Data Required..."
' If vbOK Then GoTo Endd
If Len(Me.[tech] & vbNullString) = 0 Then MsgBox "Mail Entered by is blank, you must select your name from the 'Mail Entered by combo box", _
vbInformation + vbOKOnly, "Data Required..."
' If vbOK Then GoTo Endd
' Endd:
End Sub
this works for producing desired error messages:
If Len(Me.[Report created by] & vbNullString) = 0 Then
MsgBox "This requires a VMSU technician's name selected from the " & vbNewLine & _
"'Report Created By' combo box", vbInformation + vbOKOnly, "Data Required"
If vbOK Then GoTo Endd

If Len(Me.[Cluster] & vbNullString) = 0 Then
MsgBox "This requires a Cluster selected from the " & vbNewLine & _
"'Cluster' combo box", vbInformation + vbOKOnly, "Data Required"
If vbOK Then GoTo Endd

If Len(Me.[State] & vbNullString) = 0 Then
MsgBox "This requires a State selected from the " & vbNewLine & _
"'State' combo box", vbInformation + vbOKOnly, "Data Required"


If Len(Me.[subject] & vbNullString) = 0 Then
MsgBox "Subject can not be blank this is the subject line of the e-mail", _
vbInformation + vbOKOnly, "Data Required"


If Len(Me.[msgBody] & vbNullString) = 0 Then
MsgBox "Message can not be blank, if you do not want a message to precede your report, then type 'N/A'", _
vbInformation + vbOKOnly, "Data Required"
is there a command already in vba that I could call that would simple stop processing and when the command button is clicked again the process will start from the beginning?

Carl A
03-10-2008, 06:35 AM
Try using onExit to test for your values.

Private Sub msgbody_Exit(Cancel As Integer)
If Len(Me.[msgbody] & vbNullString) = 0 Then
MsgBox "Message can not be blank, if you do not want a message to precede your report, then type 'N/A'", _
vbInformation + vbOKOnly, "Data Required"
Cancel = 1
Else
Cancel = 0
End If
End Sub

Trevor
03-10-2008, 11:48 AM
sorry, that didn't work, I even tried
if vbok then cancel = True

Trevor
03-10-2008, 11:55 AM
Ok this is annoying but it works if I change
Private Sub msgbody_Exit(Cancel As Integer)
If Len(Me.[msgbody] & vbNullString) = 0 Then
MsgBox "Message can not be blank, if you do not want a message to precede your report, then type 'N/A'", _
vbInformation + vbOKOnly, "Data Required"
Cancel = 1
Else
Cancel = 0
End If
End Sub To :
If Len(Me.[msgbody] & vbNullString) = 0 Then
MsgBox "Message can not be blank, if you do not want a message to precede your report, then type 'N/A'", _
vbInformation + vbOKOnly, "Data Required"
If vbok Then GOTo Endd
Else Cancle = 0
End If
End sub

Go figure

Carl A
03-10-2008, 12:13 PM
sorry, that didn't work, I even tried
if vbok then cancel = True

Could you upload a scaled down version so the forum users can see what you are trying to do?

I assume you are using text boxes or comboboxes. The example I posted was tested in 2000 and 2007 with no problem.

Please do use the VBA tags so you code is more readable. Just select your code snippet and click on the VBA icon.

Trevor
03-10-2008, 12:47 PM
Thanks for your help