0
我有一個登錄表單,我打算使用它來控制用戶對數據庫的訪問。我想用用戶密碼=「密碼」進行初始化,並提示用戶在首次登錄時更改密碼。我有困難更新 用於存儲我的用戶憑證的usertable。訪問登錄表單密碼更改和更新:SQL/VBA
普通登錄VBA與frm_Login相關聯:
Option Compare Database
Option Explicit
Private Sub btnLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("X_tblUsers", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.txtUserName & "'"
If rs.NoMatch Then
Me.lblWrongUser.Visible = True
Me.txtUserName.SetFocus
Exit Sub
End If
Me.lblWrongUser.Visible = False
If rs!Password <> Nz(Me.txtPassword, "") Then
Me.lblWrongPass.Visible = True
Me.txtPassword.SetFocus
Exit Sub
End If
Me.lblWrongPass.Visible = False
TempVars("UserName").Value = Me.txtUserName.Value
If Me.txtPassword = "password" Then
DoCmd.OpenForm "frm_PassChange"
End If
If rs!UserType = 3 Then
Dim prop As Property
On Error GoTo SetProperty
Set prop = CurrentDb.CreateProperty("AllowBypassKey", dbBoolean, False)
CurrentDb.Properties.Append prop
SetProperty:
If MsgBox("Turn on Bypass key?", vbYesNo, "Allow Bypass") = vbYes Then
CurrentDb.Properties("AllowByPassKey") = True
Else
CurrentDb.Properties("AllowByPassKey") = False
End If
End If
Me.Visible = False
Globals.Logging "Logon"
DoCmd.OpenForm "frm_Main"
End Sub
表格frm_PassChange調用如果密碼是「密碼」(方案已在此擴大到包括用戶請求改變以及)。在這種形式我有用戶輸入驗證新密碼2倍,然後要更新用新密碼的用戶表,但是這是行不通的:
Private Sub btnChangePass_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("X_tblUsers")
If Me.txtNewPass <> Me.txtNPConfirm Then
Me.lblPassMismatch.Visible = True
Me.txtNewPass.SetFocus
Exit Sub
End If
Me.lblPassMismatch.Visible = False
TempVars("Password").Value = Me.txtNewPass.Value
CurrentDb.Execute "Update X_tblUsers SET X_tblUsers.Password = Value(" & Me.txtNewPass.Value & ")"
Me.Visible = False
Globals.Logging "PWChange"
End Sub
如何正確執行用戶表更新?
(TKS史蒂夫·畢曉普幫助我走到這一步)
無論是否管理員,他們都不應該被允許繞過Shift鍵:) :)給他們控制訪問不完全訪問! –