Private Sub CmdLogin_Click()
On Error GoTo Err_CmdLogin_Click
If DCount("*", "qry_Login") = 0 Then
MsgBox "Invalid Username or Password", vbOKOnly, "Login Error"
[txtUserName] = Null
[txtPassword] = Null
DoCmd.GoToControl "txtUsername"
'****************************************
ElseIf [txtUserName] = DLookup("UserID", "qry_Login") And [txtPassword] = DLookup("Password", "qry_Login") _
And [txtPassExpire] > Date Then
Dim RS As Recordset
Set RS = CurrentDb.OpenRecordset("SELECT * FROM tblUserInfo")
RS.AddNew
RS("UserName") = [txtUserName].value
RS("Password") = [txtPassword].value
RS("RoleID") = [txtRoleID].value
RS("UserEmail") = [txtUserEmail].value
RS("User") = [txtUserID].value
RS("Action") = "Login"
RS("Mill") = [txtMill].value
RS("ActualUserID") = [txtActUserName].value
RS("ComputerName") = [txtComputerName].value
RS.Update
Set RS = CurrentDb.OpenRecordset("Select * From sysLog")
RS.AddNew
RS("UserID") = [txtUserName].value
RS("Action") = "LogIn"
RS("ActUserName") = [txtActUserName].value
RS("ComputerID") = [txtComputerName].value
RS.Update
RS.Close
DoCmd.Close acForm, "Login", acSaveNo
DoCmd.OpenForm "Switchboard", acNormal
'****************************************
ElseIf [txtUserName] = DLookup("UserID", "qry_Login") And [txtPassword] = DLookup("Password", "qry_Login") _
And [txtPassExpire] <= Date Then
With Me!txtUserName
.SetFocus
.SelStart = 0
.SelLength = Len(.value)
End With
DoCmd.RunCommand acCmdCopy
txtUserID = Null
txtPassword = Null
MsgBox "Password has expired, please reset your password", vbOKOnly, "Password Error"
DoCmd.OpenForm "frm_PasswordReset", acNormal
'****************************************
ElseIf [txtUserName] <> DLookup("UserID", "qry_Login") Or [txtPassword] <> DLookup("Password", "qry_Login") _
Then 'And [chkInActive] = False Then
MsgBox "Invalid Username or Password", vbOKOnly, "Login Error"
[txtUserName] = Null
[txtPassword] = Null
DoCmd.GoToControl "txtUsername"
'****************************************
End If
Exit_CmdLogin_Click:
Exit Sub
Err_CmdLogin_Click:
MsgBox Err.Description
Resume Exit_CmdLogin_Click
End Sub
Private Sub Command29_Click()
On Error GoTo Err_Command29_Click
If DCount("*", "qry_Login") = 0 Then
MsgBox "Invalid Username or Password", vbOKOnly, "Login Error"
[txtUserName] = Null
[txtPassword] = Null
DoCmd.GoToControl "txtUsername"
'****************************************
ElseIf [txtUserName] = DLookup("UserID", "qry_Login") And [txtPassword] = DLookup("Password", "qry_Login") _
And [txtPassExpire] > Date Then
Dim UserName As String
Dim Password As String
UserName = [txtUserName]
Password = [txtPassword]
RefreshODBCLinks "ODBC;DRIVER=MySQL ODBC 3.51;" & "SERVER=YNGSTOWNSHARE;UserID=" & UserName & ",pwd=" & _
Password & ";" & "Trusted_Conenction=Yes;" & "APP=2007 Microsoft Office system;DATABASE=LOGMGT;"
Dim RS As Recordset
Set RS = CurrentDb.OpenRecordset("SELECT * FROM tblUserInfo")
RS.AddNew
RS("UserName") = [txtUserName].value
RS("Password") = [txtPassword].value
RS("RoleID") = [txtRoleID].value
RS("UserEmail") = [txtUserEmail].value
RS("User") = [txtUserID].value
RS("Action") = "Login"
RS("Mill") = [txtMill].value
RS("ActualUserID") = [txtActUserName].value
RS("ComputerName") = [txtComputerName].value
RS.Update
Set RS = CurrentDb.OpenRecordset("Select * From sysLog")
RS.AddNew
RS("UserID") = [txtUserName].value
RS("Action") = "LogIn"
RS("ActUserName") = [txtActUserName].value
RS("ComputerID") = [txtComputerName].value
RS.Update
RS.Close
DoCmd.Close acForm, "Login", acSaveNo
DoCmd.OpenForm "Switchboard", acNormal
'****************************************
ElseIf [txtUserName] = DLookup("UserID", "qry_Login") And [txtPassword] = DLookup("Password", "qry_Login") _
And [txtPassExpire] <= Date Then
With Me!txtUserName
.SetFocus
.SelStart = 0
.SelLength = Len(.value)
End With
DoCmd.RunCommand acCmdCopy
txtUserID = Null
txtPassword = Null
MsgBox "Password has expired, please reset your password", vbOKOnly, "Password Error"
DoCmd.OpenForm "frm_PasswordReset", acNormal
'****************************************
ElseIf [txtUserName] <> DLookup("UserID", "qry_Login") Or [txtPassword] <> DLookup("Password", "qry_Login") _
Then 'And [chkInActive] = False Then
MsgBox "Invalid Username or Password", vbOKOnly, "Login Error"
[txtUserName] = Null
[txtPassword] = Null
DoCmd.GoToControl "txtUsername"
'****************************************
End If
Exit_Command29_Click:
Exit Sub
Err_Command29_Click:
MsgBox Err.Description
Resume Exit_Command29_Click
End Sub
Private Sub Command29_Click()
On Error GoTo Err_Command29_Click
Dim UserName As String
Dim Password As String
UserName = [txtUserName]
Password = [txtPassword]
RefreshODBCLinks "ODBC;DRIVER=MySQL ODBC 3.51;" & "SERVER=localhost;UserID=" & UserName & ",pwd=" & _
Password & ";" & "Trusted_Conenction=Yes;" & "APP=2007 Microsoft Office system;DATABASE=LogisticsMgmt_TEST;"
If DCount("*", "qry_Login") = 0 Then
MsgBox "Invalid Username or Password", vbOKOnly, "Login Error"
[txtUserName] = Null
[txtPassword] = Null
DoCmd.GoToControl "txtUsername"
'****************************************
ElseIf [txtUserName] = DLookup("UserID", "qry_Login") And [txtPassword] = DLookup("Password", "qry_Login") _
And [txtPassExpire] > Date Then
Dim RS As Recordset
Set RS = CurrentDb.OpenRecordset("SELECT * FROM tblUserInfo")
RS.AddNew
RS("UserName") = [txtUserName].value
RS("Password") = [txtPassword].value
RS("RoleID") = [txtRoleID].value
RS("UserEmail") = [txtUserEmail].value
RS("User") = [txtUserID].value
RS("Action") = "Login"
RS("Mill") = [txtMill].value
RS("ActualUserID") = [txtActUserName].value
RS("ComputerName") = [txtComputerName].value
RS.Update
Set RS = CurrentDb.OpenRecordset("Select * From sysLog")
RS.AddNew
RS("UserID") = [txtUserName].value
RS("Action") = "LogIn"
RS("ActUserName") = [txtActUserName].value
RS("ComputerID") = [txtComputerName].value
RS.Update
RS.Close
DoCmd.Close acForm, "Login", acSaveNo
DoCmd.OpenForm "Switchboard", acNormal
'****************************************
ElseIf [txtUserName] = DLookup("UserID", "qry_Login") And [txtPassword] = DLookup("Password", "qry_Login") _
And [txtPassExpire] <= Date Then
With Me!txtUserName
.SetFocus
.SelStart = 0
.SelLength = Len(.value)
End With
DoCmd.RunCommand acCmdCopy
txtUserID = Null
txtPassword = Null
MsgBox "Password has expired, please reset your password", vbOKOnly, "Password Error"
DoCmd.OpenForm "frm_PasswordReset", acNormal
'****************************************
ElseIf [txtUserName] <> DLookup("UserID", "qry_Login") Or [txtPassword] <> DLookup("Password", "qry_Login") _
Then 'And [chkInActive] = False Then
MsgBox "Invalid Username or Password", vbOKOnly, "Login Error"
[txtUserName] = Null
[txtPassword] = Null
DoCmd.GoToControl "txtUsername"
'****************************************
End If
Exit_Command29_Click:
Exit Sub
Err_Command29_Click:
MsgBox Err.Description
Resume Exit_Command29_Click
End Sub
well, what you need is on login to modify the connection information of those linked table, using the login specified by the user.
however, in access 2007, I don't know if the code I used for lower version of access will work there...