2011-03-11 80 views
0

我創建了一個Microsoft Access 2007數據庫。這是創建兩種形式。 1.僱員形式。 表名「tbl employee」:ID,IC NO,姓名,辦公室分支。 2.login形式。 : 表名「tble User」:UID,用戶名,密碼,啓用,全名。Access 2007 - 獲取VB用戶登錄並記錄最後修改後的表單

像往常一樣,當我登錄的用戶名(使用組合框)和密碼(使用文本框)登錄表單正常工作,因爲我使用VB,如下圖所示: -

Private Sub cbo_User_AfterUpdate() 
Me.txt_Password = Empty 
    Me.txt_Password.Enabled = True 
    Me.txt_Password.SetFocus 
End Sub 

Private Sub cmd_OK_Click() 
'test the stored password is = to the manually entered password 
    If Me.cbo_User.Column(2) = Me.txt_Password Then 
     DoCmd.OpenForm "fm_employee", acNormal 
     DoCmd.Close acForm, "frm_Login" 
     DoCmd.Close acForm, "fm_switchboard" 
    Else 'wrong match 
     MsgBox "Wrong password entered." & _ 
      vbCrLf & "Please re-enter password.", _ 
      vbExclamation, "Invalid Password" 
     Me.txt_Password.SetFocus 'places the cursor in password control 
    End If 
    'If User Enters incorrect password 3 times database will shutdown 

    intLogonAttempts = intLogonAttempts + 1 
    If intLogonAttempts > 3 Then 
     MsgBox "You do not have access to this database.Please contact admin.", _ 
       vbCritical, "Restricted Access!" 
     Application.Quit 
    End If 
End Sub 

現在,我需要幫助如何在用戶客戶端修改並保存員工表單中的每條記錄後,從登錄表單中獲取全名或用戶名並記錄到該字段中。

注:登錄用戶超過1

+0

如果您可以在您的問題中縮進代碼,這將更容易閱讀。縮進4個空格,並保存格式。 – 2011-03-11 02:17:36

+1

這是在Access中的VBA編碼嗎?如果是這樣,那麼'Me.txt_Password = Empty'這行不能正確,因爲'Empty'應該是'Null'。我也質疑你在這裏做什麼 - 這是虛假的安全,並沒有真正做任何事情來保護你的數據。如果您正在使用它來控制程序流,那麼使用Windows登錄名稱可能會更好,因爲您不再需要擔心密碼。 – 2011-03-12 00:51:36

回答

1

如果我理解正確的話,你想記錄誰使更改基於誰是到數據庫中記錄的記錄。在這種情況下,隱藏而不是關閉frmLogin。你可以用Me.Visible = false來做到這一點。然後,您可以爲表單fm_employee的BeforeUpdate事件創建一個事件過程。在該事件過程中,將誰修改記錄的字段設置爲等於Forms!frmLogin!cbo_User。

+0

Pse糾正我,如果我錯了,在我把代碼之前,我創建了一個字段在我的表員工,這是最後修改。從場中前事件屬性被示出這樣的: - 第一行中:Private Sub Last_Modified_BeforeUpdate(取消作爲整數) 第二行:表單frm_Login cbo_User >>>(該代碼成爲紅色) !第三行:End Sub 順便說一句,我真的很感謝你的投入。 – user654603 2011-03-14 02:16:04

+0

除非您允許用戶編輯Last_Modified字段,否則該字段上的事件將永遠不會觸發。要創建私人小組Form_BeforeUpdate,放在了功能如下: Last_Modified.Value = NOW() Last_Modified_By.Value =形式frmLogin cbo_User 是否幫助!? – TheOtherTimDuncan 2011-03-15 12:20:35