Text Box validation (1 Viewer)

siddnave2

Registered User.
Local time
Tomorrow, 00:56
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:26
Joined
May 7, 2009
Messages
19,248
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
 

siddnave2

Registered User.
Local time
Tomorrow, 00:56
Joined
Nov 19, 2015
Messages
16
Hi arnelgp,

Thanks the solution worked out for me.

Rgds,
Naveen.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:26
Joined
May 7, 2009
Messages
19,248
your welcome pal
 

Users who are viewing this thread

Top Bottom