Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form validation not working

Status
Not open for further replies.

PROXI

Vendor
Sep 16, 2003
136
0
0
US
Hello,

I have been trying to get this code to work for me and I just can't seem to get it to work right. It appears that the code is just skipping over my first "If" clause and going straight to the sql. Any help would be greatly appreciated.

Code:
Private Sub Command10_Click()
Dim strSQL As String
Dim resp As Long
Dim ctl As Control


    If Nz(Me.PPA_NBR, "") & "" <> "" Then
        MsgBox "Please input an administrator number", vbOKOnly, "Input Error"
        GoTo Command10_Click_Exit
    Else
        strSQL = "INSERT INTO PPA_Watchlist (PPA_NBR, PPA_NAME, Region, Comment, Watchlist)" _
            & "Values ('" & PPA_NBR & "','" & PPANAME & "','" & Region & "','" & Comment & "','Yes');"
        DoCmd.RunSQL strSQL
        
        resp = MsgBox("Would you like to input another administrator?", vbYesNoCancel, "Are you finished?")
                Select Case resp
                    Case vbYes
                        Me.PPA_NBR = ""
                        Me.PPANAME = ""
                        Me.Region = ""
                        Me.Comment = ""
                        Me.PPA_NBR.SetFocus
                    Case vbNo
                        DoCmd.Close
                    Case vbCancel
                        Cancel = True
                        strSQL = "DELETE * FROM " _
                        & "PPA_Watchlist WHERE PPA_NBR = '" & PPA_NBR & "';"
                        DoCmd.RunSQL strSQL
                End Select
    End If
    
Command10_Click_Exit:
    Exit Sub
End Sub

Thanks,

PROXI
 
I'm retarded. Had the "If" statement set to <> instead of =.

Code:
    If Nz(Me.PPA_NBR, "") & "" = "" Then
        MsgBox "Please input an administrator number", vbOKOnly, "Input Error"
        GoTo Command10_Click_Exit

Thanks,

PROXI
 
Note that you don't need that extra & "". The following will behave exactly the same way:

Code:
    If Nz(Me.PPA_NBR, "") = "" Then
        MsgBox "Please input an administrator number", vbOKOnly, "Input Error"
        GoTo Command10_Click_Exit
 
To cover Null, ZeroLength and SpaceOnly:
If Trim(Me!PPA_NBR & "") <> "" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top