我是新手,我用的ACCESS製作帳號密碼登入後,顯示的名稱怎麼都是資料表的第1個人,我想要自動帶出這個帳號正確的使用者名稱請問如何解決阿~
Private Sub Command5_Click()
If IsNull(Me!Text1) = True Or Me!Text1 = "" Then
MsgBox "帳號欄空白!"
Text1.SetFocus '<====回欄位1
Exit Sub
Else
If IsNull(Me!Text3) = True Or Me!Text3 = "" Then
MsgBox "密碼欄空白!"
Text3.SetFocus
Exit Sub
End If
End If
If IsNull(DLookup("user", "tbl_User", "user='" & Text1 & "'")) Then
MsgBox "帳號錯誤"
Text1.SetFocus '<====回欄位1等帳號正確在執行下方驗證密碼
Exit Sub
Else
If IsNull(DLookup("userpassword", "tbl_User", "user='" & Text1 & "' and userpassword='" & Text3 & "'")) Then
MsgBox "密碼錯誤"
Text3.SetFocus '<====回欄位2
Exit Sub
End If
End If
MsgBox "登入成功"
DoCmd.OpenForm "開始介面"
Forms![開始介面]![txtUser] = (DLookup("Name", "tbl_User", "user = [user]")) '這個是我寫要帶出姓名的部分~
DoCmd.Close acForm, "登入"
End Sub
If IsNull(DLookup("userpassword", "tbl_User", "user='" & Text1 & "' and userpassword='" & Text3 & "'")) Then
MsgBox "密碼錯誤"
Text3.SetFocus '<====回欄位2
Exit Sub
End If
....
Forms![開始介面]![txtUser] = (DLookup("Name", "tbl_User", "user = [user]")) '這個是我寫要帶出姓名的部分~
改成
username = DLookup("Name", "tbl_User", "user='" & Text1 & "' and userpassword='" & Text3 & "'")
If IsNull(username) Then
MsgBox "密碼錯誤"
Text3.SetFocus '<====回欄位2
Exit Sub
End If
....
Forms![開始介面]![txtUser] = username '這個是我寫要帶出姓名的部分~
試試看
海綿寶寶
真感謝你~~
如果我要加入權限判斷,開啟不同的表單,要怎麼寫呢?
權限在我的資料表叫"UserLevel"
抱歉第一次學 這麼麻煩的請教您~