iT邦幫忙

0

access登入後顯示姓名問題

我是新手,我用的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
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2020-10-04 20:19:22
最佳解答
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 '這個是我寫要帶出姓名的部分~

試試看

另外,點這裡是我這次鐵人賽唯一的一篇文章,喜歡的話左上角點 Like

海綿寶寶
真感謝你~~
如果我要加入權限判斷,開啟不同的表單,要怎麼寫呢?
權限在我的資料表叫"UserLevel"
抱歉第一次學 這麼麻煩的請教您~

我要發表回答

立即登入回答