Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2003
    Posts
    41

    Unanswered: Access not validating code

    Good day,

    I something really weird going on with the code below. Basically 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

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    Did you try to use IsNull or IsEmpty

    i.e

    If Not IsNull(txtcasenum) then
    ..... you code
    Endif

  3. #3
    Join Date
    Jul 2003
    Posts
    41
    I tried both and they didn't work.
    Any other sugguestions?

    Thanks

  4. #4
    Join Date
    Jun 2004
    Posts
    55

    Arrow

    Use the IsNull Command and also make a variable called Response so..

    Dim Response As String

    If IsNull(txtcasenum.Value) then
    Response = MsgBox ("You must enter a Case Number....", vbOkOnly + vbInformation)
    Exit Sub
    End If

    My other suggestion would be to use the ElseIf you kinda get:

    Dim Response As String, SqlStr as String

    If IsNull(txtcasenum.Value) then
    Response = MsgBox ("You must enter a Case Number....", vbOkOnly + vbInformation)
    ElseIf IsNull (cbostatus.Value ) then
    Repsonse =
    .
    .
    .
    .
    Else

    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 If
    Last edited by dwil2g1; 06-25-04 at 10:36.

  5. #5
    Join Date
    Jul 2003
    Posts
    41
    Thanks for the relies, it is working now.

Posting Permissions

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