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
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