Good Evening,
I found a code from another website, that will show you the Computer/UserName/Connect information of all users within the database. I'm not much of a programmer, and was wondering what type of code I need to put where to get this particular code to be able to capture which user logged on by udsername...?
When someone logs onto my database, they enter a username and password which is stored using tempvars (something like that). Below is the code for my log on form, and below that is the code to this user list. Any ideas on what I edit?
I found a code from another website, that will show you the Computer/UserName/Connect information of all users within the database. I'm not much of a programmer, and was wondering what type of code I need to put where to get this particular code to be able to capture which user logged on by udsername...?
When someone logs onto my database, they enter a username and password which is stored using tempvars (something like that). Below is the code for my log on form, and below that is the code to this user list. Any ideas on what I edit?
Code:
Private Function GenerateUserList()
'The User List Schema information requires this magic number. For anyone
'who may be interested, this number is called a GUID or Globally Unique
'Identifier - sorry for digressing
Const conUsers = "{947bb102-5d43-11d1-bdbf-00c04fb92675}"
Dim cnn As ADODB.Connection, fld As ADODB.Field, strUser As String
Dim rst As ADODB.Recordset, intUser As Integer, varValue As Variant
Set cnn = CurrentProject.Connection
Set rst = cnn.OpenSchema(Schema:=adSchemaProviderSpecific, SchemaID:=conUsers)
'Set List Box Heading
strUser = "Computer;UserName;Connected?;Suspect?"
With rst 'fills Recordset (rst) with User List data
Do Until .EOF
intUser = intUser + 1
For Each fld In .Fields
varValue = fld.Value
'Some of the return values are Null-Terminated Strings, if
'so strip them off
If InStr(varValue, vbNullChar) > 0 Then
varValue = Left(varValue, InStr(varValue, vbNullChar) - 1)
End If
strUser = strUser & ";" & varValue
Next
.MoveNext
Loop
End With
Me!txtTotalNumOfUsers = intUser 'Total # of Users
'Set up List Box Parameters
Me!lstUsers.ColumnCount = 4
Me!lstUsers.RowSourceType = "Value List"
Me!lstUsers.ColumnHeads = False
lstUsers.RowSource = strUser 'populate the List Box
'Routine cleanup chores
Set fld = Nothing
Set rst = Nothing
Set cnn = Nothing
End Function
Code:
Private Sub Command1_Click()
Dim userLevel As Integer
If IsNull(Me.txtLoginID) Then
MsgBox "Please enter LoginID", vbInformation, "LoginID Required"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter password", vbInformation, "Password Required"
Me.txtPassword.SetFocus
Else
'process the job
If (IsNull(DLookup("User_Login", "tblUser", "User_login ='" & Me.txtLoginID.Value & "'"))) Or _
(IsNull(DLookup("Password", "tblUser", "Password ='" & Me.txtPassword.Value & "'"))) Then
MsgBox "Incorrect LoginID or Password"
Else
userLevel = DLookup("UserSecurity", "tblUser", "User_Login = '" & Me.txtLoginID.Value & "'")
If userLevel = 1 Then
MsgBox "LoginID and Password Correct"
TempVars.Add "sUsername", Me.txtLoginID.Value
DoCmd.Close
DoCmd.Close acForm, "Login", acSaveYes
DoCmd.OpenForm "frmWhatisnew"
Else
MsgBox "LoginID and Password Correct"
TempVars.Add "sUsername", Me.txtLoginID.Value
DoCmd.Close
DoCmd.Close acForm, "Order Review", acSaveYes
DoCmd.OpenForm "frmNavigation_controlled_User"
End If
End If
End If
End Sub