i got 3 type username and password :
1. boss
2. manager
3. staff
how should i check if the username is exist then pop up msgbox error else add username and password to database
1. boss
2. manager
3. staff
how should i check if the username is exist then pop up msgbox error else add username and password to database
Code:
Dim rss As New ADODB.Recordset
Dim strID As String
Dim cnn As New ADODB.Connection
Dim strCNString As String
Dim intFound As Integer
strCNString = "Data Source=" & App.Path & "\PayrollBakeryDB.mdb"
cnn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
cnn.ConnectionString = strCNString
cnn.Open
If txtPassword.Text <> txtC_Password.Text Then
MsgBox "Password must be same with confirm pasword ! ", vbExclamation, "Error"
Else
With rss
.Open "SELECT emp_id, s_username,s_password, m_username,m_password, b_username,b_password FROM Employees", cnn, adOpenDynamic, adLockOptimistic
Do Until .EOF
If txtSearch.Text = !emp_id Then
If txtUserName.Text = !s_username Then
intFounds = 2
MsgBox "UserName aleardy use by other staff !!", vbExclamation, "Create Account"
Else
If txtType.Text = "boss" Then
!b_username = txtUserName.Text
!b_password = txtPassword.Text
.Update
MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
txtSearch.Text = ""
txtName.Text = ""
txtType.Text = ""
txtUserName.Text = ""
txtPassword.Text = ""
txtC_Password.Text = ""
intFounds = 1
ElseIf txtType.Text = "manager" Then
!m_username = txtUserName.Text
!m_password = txtPassword.Text
.Update
MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
txtSearch.Text = ""
txtName.Text = ""
txtType.Text = ""
txtUserName.Text = ""
txtPassword.Text = ""
txtC_Password.Text = ""
intFounds = 1
ElseIf txtType.Text = "staff" Then
!s_username = txtUserName.Text
!s_password = txtPassword.Text
.Update
MsgBox "Create Succeeded!!", vbExclamation, "Create Account"
txtSearch.Text = ""
txtName.Text = ""
txtType.Text = ""
txtUserName.Text = ""
txtPassword.Text = ""
txtC_Password.Text = ""
intFounds = 1
End If
End If
End If
.MoveNext
Loop
.MoveFirst
If intFounds = 0 Then
MsgBox "Employee ID not found !", vbExclamation, "Search"
ElseIf intFounds = 2 Then
MsgBox "Please change username and try againt !", vbExclamation, "Error"
txtUserName.Text = ""
txtPassword.Text = ""
txtC_Password.Text = ""
End If
End With
Exit Sub
cnn.Close
End If
cnn.Close
Comment