Text Box validation

siddnave2

Registered User.
Local time
Today, 09:59
Joined
Nov 19, 2015
Messages
16
Hi,

This is code for Inserting New user record before which i am validating the text field where it should not be null. But without validation record getting inserted to table. Can some one suggest where i am wrong.

Private Sub cmdadd_Click()
'Check Null Text boxes
If IsNull(Me.TxtUserName) Then
MsgBox "Please Enter User Name", vbInformation, "User Name Required!"
Me.TxtUserName.SetFocus

ElseIf IsNull(Me.TxtLogin) Then
MsgBox "Please Enter User Login", vbInformation, "User Login Required!"
Me.TxtLogin.SetFocus

ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Password", vbInformation, "Password Required!"
Me.txtPassword.SetFocus

ElseIf IsNull(Me.CmbSecurity) Then
MsgBox "Please Select User Security", vbInformation, "User Security Required!"
Me.CmbSecurity.SetFocus

Else
'Add Records
CurrentDb.Execute "INSERT INTO tbluser(UserName,UserLogin,Password,UserSecurity) VALUES ('" & Me.TxtUserName & "','" & TxtLogin & "','" & txtPassword & "','" & Me.CmbSecurity & "')"
MsgBox "New User Created", vbInformation, "New User Added!"

'refresh data in list on form
frmUsersubform.Form.Requery

' Clear Fields
Me.TxtUserName = ""
Me.TxtLogin = ""
Me.txtPassword = ""
Me.CmbSecurity = ""

'focus on UserName
Me.TxtUserName.SetFocus
End If
End Sub
 
If IsNull(Me.TxtUserName) Then
MsgBox "Please Enter User Name", vbInformation, "User Name Required!"
Me.TxtUserName.SetFocus
Exit Sub
End If
If IsNull(Me.TxtLogin) Then
MsgBox "Please Enter User Login", vbInformation, "User Login Required!"
Me.TxtLogin.SetFocus
Exit Sub
End If
If IsNull(Me.txtPassword) Then
MsgBox "Please Enter Password", vbInformation, "Password Required!"
Me.txtPassword.SetFocus
Exit Sub
End If
If IsNull(Me.CmbSecurity) Then
MsgBox "Please Select User Security", vbInformation, "User Security Required!"
Me.CmbSecurity.SetFocus
Exit Sub
End If

'Add Records
CurrentDb.Execute "INSERT INTO tbluser(UserName,UserLogin,Password,UserSecurity) VALUES ('" & Me.TxtUserName & "','" & TxtLogin & "','" & txtPassword & "','" & Me.CmbSecurity & "')"
MsgBox "New User Created", vbInformation, "New User Added!"

'refresh data in list on form
frmUsersubform.Form.Requery

' Clear Fields
Me.TxtUserName = ""
Me.TxtLogin = ""
Me.txtPassword = ""
Me.CmbSecurity = ""

'focus on UserName
Me.TxtUserName.SetFocus
 
Hi arnelgp,

Thanks the solution worked out for me.

Rgds,
Naveen.
 
your welcome pal
 

Users who are viewing this thread

Back
Top Bottom