justlearning2003
Technical User
Good day,
It is something really weird going on with the code below. I am tring to validate textboxes on my form. But what is happening is that if I leave any or all of the textboxes blank, access skips my code validating empty boxes and jumps right into the sql down below. Any ideas on this one? I am using Access 2K.
Private Sub cmdopensubmit_Click()
If txtcasenum.Value = "" Then
MsgBox "You must enter a Case Number...."
Exit Sub
End If
If cbostatus.Value = "" Then
MsgBox "You must enter the Status....", vbCritical
Exit Sub
End If
If referraltype.Value = "" Then
MsgBox "You must enter Referral Type....", vbCritical
Exit Sub
End If
If txtopendate.Value = "" Then
MsgBox "You must enter a Open Date....", vbCritical
Exit Sub
End If
If txtagentidopen.Value = "" Then
MsgBox "You must enter the Agent ID who opened the case....", vbCritical
Exit Sub
End If
If txtworked.Value = "" Then
MsgBox "You must enter if the case has been worked or not....", vbCritical
Exit Sub
End If
If cbowaiting.Value = "" Then
MsgBox "You must verify if the case is done or not....", vbCritical
Exit Sub
End If
If txtrecentfollowup.Value = "" Then
MsgBox "You must the follow up date....", vbCritical
Exit Sub
End If
If txtextracomments.Value = "" Then
MsgBox "You must the comments....", vbCritical
Exit Sub
End If
Dim SqlStr As String
SqlStr = "INSERT INTO tblopenref (casenum, status, referraltype, opendate, agentidopen, worked, waiting, waitingothercomments, recentfollowup, extracomments, closedate) Values" _
& "('" & Forms!frmopenrefv2!txtcasenum & "', '" & Forms!frmopenrefv2!cbostatus & "','" & Forms!frmopenrefv2!referraltype & "', #" & Forms!frmopenrefv2!txtopendate & "#, '" & Forms!frmopenrefv2!txtagentidopen & "', '" & Forms!frmopenrefv2!txtworked & "', '" & Forms!frmopenrefv2!cbowaiting & "', '" & Forms!frmopenrefv2!waitingothercomments & "', #" & Forms!frmopenrefv2!txtrecentfollowup & "#, '" & Forms!frmopenrefv2!txtextracomments & "', #" & Forms!frmopenrefv2!closedate & "#)"
DoCmd.RunSQL (SqlStr)
End Sub
It is something really weird going on with the code below. I am tring to validate textboxes on my form. But what is happening is that if I leave any or all of the textboxes blank, access skips my code validating empty boxes and jumps right into the sql down below. Any ideas on this one? I am using Access 2K.
Private Sub cmdopensubmit_Click()
If txtcasenum.Value = "" Then
MsgBox "You must enter a Case Number...."
Exit Sub
End If
If cbostatus.Value = "" Then
MsgBox "You must enter the Status....", vbCritical
Exit Sub
End If
If referraltype.Value = "" Then
MsgBox "You must enter Referral Type....", vbCritical
Exit Sub
End If
If txtopendate.Value = "" Then
MsgBox "You must enter a Open Date....", vbCritical
Exit Sub
End If
If txtagentidopen.Value = "" Then
MsgBox "You must enter the Agent ID who opened the case....", vbCritical
Exit Sub
End If
If txtworked.Value = "" Then
MsgBox "You must enter if the case has been worked or not....", vbCritical
Exit Sub
End If
If cbowaiting.Value = "" Then
MsgBox "You must verify if the case is done or not....", vbCritical
Exit Sub
End If
If txtrecentfollowup.Value = "" Then
MsgBox "You must the follow up date....", vbCritical
Exit Sub
End If
If txtextracomments.Value = "" Then
MsgBox "You must the comments....", vbCritical
Exit Sub
End If
Dim SqlStr As String
SqlStr = "INSERT INTO tblopenref (casenum, status, referraltype, opendate, agentidopen, worked, waiting, waitingothercomments, recentfollowup, extracomments, closedate) Values" _
& "('" & Forms!frmopenrefv2!txtcasenum & "', '" & Forms!frmopenrefv2!cbostatus & "','" & Forms!frmopenrefv2!referraltype & "', #" & Forms!frmopenrefv2!txtopendate & "#, '" & Forms!frmopenrefv2!txtagentidopen & "', '" & Forms!frmopenrefv2!txtworked & "', '" & Forms!frmopenrefv2!cbowaiting & "', '" & Forms!frmopenrefv2!waitingothercomments & "', #" & Forms!frmopenrefv2!txtrecentfollowup & "#, '" & Forms!frmopenrefv2!txtextracomments & "', #" & Forms!frmopenrefv2!closedate & "#)"
DoCmd.RunSQL (SqlStr)
End Sub