User Management System
User Management System
User Management System
frmLogin Option Explicit Private Sub btnAddUser_Click() Unload Me frmAddUser.Show End Sub Private Sub btnAddUser_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnAddUser.BackColor = &HFFFF00 btnOK.BackColor = &H8000000F btnCancel.BackColor = &H8000000F End Sub Private Sub btnCancel_Click() Dim res As Integer res = MsgBox("Are you sure you want to cancel?", vbYesNo + vbDefaultButton2 + vbQuestion, "Exit?") If res = vbYes Then End End If End Sub Private Sub btnCancel_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnCancel.BackColor = &HFFFF00 btnOK.BackColor = &H8000000F btnAddUser.BackColor = &H8000000F End Sub Private Sub btnOK_Click() Dim rst As New ADODB.Recordset Dim SQL As String
If txtUserName.Text = "" Or txtPassword.Text = "" Then MsgBox "Incomplete!", , "Log-in Error!" Else SQL = "Select*From Users Where Username = '" + txtUserName.Text + "' And Password = '" + txtPassword.Text + "'" rst.Open SQL, Conn, adOpenDynamic, adLockPessimistic If Not (rst.EOF Or rst.BOF) Then Unload Me frmUserMngt.Show frmUserMngt.lblWelcome.Caption = "Welcome " & rst!UserName & "!" frmUserMngt.lblLogAccess = rst!AccessLevel frmUserMngt.lblAccess.Caption = "Logged-in As " & rst!AccessLevel Else MsgBox "Incorrect log-in!", , "Log-in Error!" End If End If End Sub Private Sub btnOK_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnOK.BackColor = &HFFFF00 btnCancel.BackColor = &H8000000F btnAddUser.BackColor = &H8000000F End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnOK.BackColor = &H8000000F btnCancel.BackColor = &H8000000F btnAddUser.BackColor = &H8000000F End Sub
res = MsgBox("Are you sure you want to cancel?", vbYesNo + vbDefaultButton2 + vbQuestion, "Exit?") If res = vbYes Then Unload Me frmLogin.Show End If End Sub Private Sub btnOK_Click() Dim rst As New ADODB.Recordset If txtUserName.Text = "" Or txtPassword.Text = "" Or cboAccessLevel.Text = "" Then MsgBox "Incomplete data!", vbExclamation, "Registration Error!" txtUserName.SetFocus Else SQL = "Select*From Users Where Username = '" + txtUserName.Text + "'" rst.Open SQL, Conn, adOpenDynamic, adLockPessimistic If Not (rst.EOF Or rst.BOF) Then MsgBox "Username already registered. Please enter new username!", vbExclamation, "Registration Error!" txtUserName.Text = "" txtPassword.Text = "" cboAccessLevel.Text = "" txtUserName.SetFocus Else rst.AddNew rst!UserName = txtUserName.Text rst!Password = txtPassword.Text rst!AccessLevel = cboAccessLevel.Text rst.Update MsgBox "New user added!", vbInformation, "Success!" Unload Me frmLogin.Show End If End If End Sub
Private Sub Form_Load() Dim rst As New ADODB.Recordset rst.Open "SELECT*From Access", Conn, adOpenDynamic, adLockPessimistic rst.MoveFirst While rst.EOF = False cboAccessLevel.AddItem rst!AccessLevel rst.MoveNext Wend End Sub Private Sub btnCancel_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnCancel.BackColor = &HFFFF00 btnOK.BackColor = &H8000000F End Sub Private Sub btnOK_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnOK.BackColor = &HFFFF00 btnCancel.BackColor = &H8000000F End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnOK.BackColor = &H8000000F btnCancel.BackColor = &H8000000F End Sub
Admin Window
User Window
Admin Power Disabled frmUserMngt Option Explicit Private Sub LoadList() Dim rst As New ADODB.Recordset
rst.Open "SELECT*From Users Order By Username", Conn, adOpenDynamic, adLockPessimistic lvwUsers.ListItems.Clear rst.MoveFirst While rst.EOF = False lvwUsers.ListItems.Add , , rst!ID lvwUsers.ListItems(lvwUsers.ListItems.Count).ListSubItems.Add , , rst!UserName lvwUsers.ListItems(lvwUsers.ListItems.Count).ListSubItems.Add , , rst!AccessLevel rst.MoveNext Wend End Sub Private Sub LoadTextBox() Dim rst As New ADODB.Recordset rst.Open "SELECT*From Users Where ID = val('" + lvwUsers.SelectedItem.Text + "')", Conn, adOpenDynamic, adLockPessimistic rst.MoveFirst While rst.EOF = False txtUserName.Text = rst!UserName txtPassword.Text = rst!Password
cboAccessLevel.Text = rst!AccessLevel rst.MoveNext Wend End Sub Private Sub btnDelete_Click() Dim rst As New ADODB.Recordset Dim ask As Integer If txtUserName.Text = "" Then MsgBox "Please select an item!", vbExclamation, "No Item!" Else
ask = MsgBox("Are you sure you want to delete user?", vbQuestion + vbDefaultButton2 + vbYesNo, "Deleting...") If ask = vbYes Then rst.Open "SELECT*FROM Users Where ID = val('" + lvwUsers.SelectedItem.Text + "')", Conn, adOpenDynamic, adLockPessimistic rst.Delete txtUserName.Text = "" txtPassword.Text = "" cboAccessLevel.Text = "" txtUserName.Enabled = False txtPassword.Enabled = False cboAccessLevel.Enabled = False Call LoadList End If End If End Sub Private Sub btnDelete_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnDelete.BackColor = &HFFFF00 btnUpdate.BackColor = &H8000000F End Sub Private Sub btnUpdate_Click() Dim rst As New ADODB.Recordset Dim ask As Integer
If txtUserName.Text = "" Then MsgBox "Please select an item!", vbExclamation, "No Item!" Else ask = MsgBox("Are you sure you want to save changes?", vbQuestion + vbDefaultButton2 + vbYesNo, "Updating...") If ask = vbYes Then rst.Open "SELECT*FROM Users Where ID = val('" + lvwUsers.SelectedItem.Text + "')", Conn, adOpenDynamic, adLockPessimistic rst!UserName = txtUserName.Text rst!Password = txtPassword.Text rst!AccessLevel = cboAccessLevel.Text rst.Update txtUserName.Text = "" txtPassword.Text = "" cboAccessLevel.Text = "" txtUserName.Enabled = False txtPassword.Enabled = False cboAccessLevel.Enabled = False Call LoadList End If End If End Sub Private Sub btnUpdate_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnUpdate.BackColor = &HFFFF00 btnDelete.BackColor = &H8000000F End Sub Private Sub Form_Activate() If lblAccess.Caption = "Logged-in As User" Then btnUpdate.Enabled = False btnDelete.Enabled = False mnuAdPow.Enabled = False ElseIf lblAccess.Caption = "Logged-in As Administrator" Then btnUpdate.Enabled = True btnDelete.Enabled = True mnuAdPow.Enabled = True
End If txtUserName.Enabled = False txtPassword.Enabled = False cboAccessLevel.Enabled = False End Sub Private Sub Form_Load() Call LoadList Dim rst As New ADODB.Recordset rst.Open "SELECT*From Access", Conn, adOpenDynamic, adLockPessimistic rst.MoveFirst While rst.EOF = False cboAccessLevel.AddItem rst!AccessLevel rst.MoveNext Wend End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) btnUpdate.BackColor = &H8000000F btnDelete.BackColor = &H8000000F End Sub Private Sub lvwUsers_Click() Call LoadTextBox If lblAccess.Caption = "Logged-in As User" Then txtUserName.Enabled = False txtPassword.Enabled = False cboAccessLevel.Enabled = False ElseIf lblAccess.Caption = "Logged-in As Administrator" Then txtUserName.Enabled = True txtPassword.Enabled = True cboAccessLevel.Enabled = True End If End Sub Private Sub mnuAdPow_Click() mnuAdPow.Checked = Not (mnuAdPow.Checked) If mnuAdPow.Checked = True Then txtPassword.PasswordChar = "" Else txtPassword.PasswordChar = "?"
End If End Sub Private Sub mnuExit_Click() Dim res As Integer res = MsgBox("Are you sure you want to exit?", vbYesNo + vbDefaultButton2 + vbQuestion, "Exit?") If res = vbYes Then End End If End Sub Private Sub mnuLogoff_Click() Dim res As Integer res = MsgBox("Are you sure you want to log-off?", vbYesNo + vbDefaultButton2 + vbQuestion, "Logging - Off...?") If res = vbYes Then Unload Me frmLogin.Show End If End Sub Private Sub mnuPrint_Click() Dim rst As New ADODB.Recordset SQL = "Select*From Users Order By Username" rst.Open SQL, Conn, adOpenDynamic, adLockPessimistic Set rptManage.DataSource = rst rptManage.Show rptManage.ZOrder End Sub Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button) Select Case Button.Key Case "logoff" Call mnuLogoff_Click Case "exit" Call mnuExit_Click Case "print" Call mnuPrint_Click End Select End Sub Private Sub txtSearch_Change()
Dim rst As New ADODB.Recordset Dim SQL As String SQL = "SELECT*FROM Users WHERE Username LIKE '" + txtSearch.Text + "%" + "' Order By Username" rst.Open SQL, Conn, adOpenDynamic, adLockPessimistic lvwUsers.ListItems.Clear If Not (rst.BOF And rst.EOF) Then rst.MoveFirst While rst.EOF = False lvwUsers.ListItems.Add , , rst!ID lvwUsers.ListItems(lvwUsers.ListItems.Count).ListSubItems.Add , , rst!UserName lvwUsers.ListItems(lvwUsers.ListItems.Count).ListSubItems.Add , , rst!AccessLevel rst.MoveNext Wend Else MsgBox "No record found!", vbExclamation, "Search..." End If End Sub Private Sub txtSearch_Click() txtSearch.Text = "" End Sub Module1 Option Explicit Global Conn As New ADODB.Connection Global SQL As String Private Sub Main() Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Practice.mdb;Persist Security Info=False" Conn.Open frmFlash.Show End Sub
rptManage