2011-06-01 59 views
1

我環顧四周,我還沒有找到答案,所以我希望有人能幫助我。在不使用VBA的情況下使用宏在Microsoft Access中創建登錄表單。

我創建使用Microsoft Access系統中,如果我有一個包含用戶名和密碼等各種領域,如出生日期一成員表等

我想創建一個表格,用戶可以輸入用戶名和密碼。通過單擊此表單上的按鈕,這些詳細信息將與成員表中的用戶名和密碼進行覈對。如果詳細信息匹配,則會顯示一條消息,說明他們已登錄。如果在表中找不到詳細信息,則會顯示一條消息,指出詳細信息不正確。

如何在不使用VBA的情況下做到這一點?

我已經創建了一個名爲loginform有兩個文本框loginusernameloginpassword形式開始。

我應該從哪裏出發?

+4

爲什麼不使用VBA?將是最簡單的方法。 – 2011-06-01 20:30:58

+0

我正準備參加一個考試,我必須在定時環境中創建我的系統,除了之前我沒有任何外部幫助。我見過的所有vba都很長很複雜,我只是無法記住它的心臟。如果沒有其他方法,我可以嘗試。 – 2011-06-01 21:01:40

+2

如果您認爲VBA很長且很複雜,那麼您將會陷入麻煩,認爲您可以在不使用VBA的情況下在Access中執行此操作。 – HardCode 2011-06-01 21:23:50

回答

5

VBA解決方案不應該那麼複雜。一個快速和骯髒的解決方案:

Dim Result as Variant 

Result=Dlookup("Password","tblMembers","UserName='" & nz(loginusername.value,"") & "'") 
If nz(Result,"")<>nz([login password].value,"") Then 
    MsgBox "Invalid password" 
Else 
    MsgBox "Password correct" 
End If 
+0

非常感謝!完美的作品。現在嘗試和記住這個心臟..再次感謝! – 2011-06-02 10:00:00

1
'set the variables 
Dim UN As String 
Dim PW As String 
Dim user, pass As Boolean 
'make sure none of the fields are null, or blank 
UN = Text 
PW = Text 
If IsNull(Username) Then 
MsgBox "You must enter a username." 
Username.SetFocus 
Else 
'assign true to user 
user = True 
End If 
If IsNull(Password) Then 
MsgBox "You must enter a password." 
Password.SetFocus 
Else 
pass = True 
End If 
If user = True And pass = True Then 
UN = DLookup("[Username]", "LoginTable", "[Username]= '" & Me.Username & "'") 
PW = DLookup("[Password]", "LoginTable", "[Password] = '" & Me.Password & "'") 
End If 
If Me.DummyUser = Me.Username And Me.DummyPass = Me.Password Then 
MsgBox "Access granted." 
Else 
MsgBox "Access denied." 
End If 
相關問題