ms-access - MS Access - 登录
问题描述
当用户登录时,我希望他们的用户名显示在主菜单的标签中。这是我的代码。此时允许登录表单检查输入的详细信息并将它们与员工表进行比较以允许访问主页表单。
Option Compare Database
Option Explicit
Private Sub ButtonLogin_Click()
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("Employees", 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("EmployeeType") = rs!EmployeeType_ID.Value
DoCmd.OpenForm "Home"
DoCmd.Close acForm, Me.Name
End Sub
在这个阶段之后,我被困在“主页”表单的代码中以显示刚刚登录的用户(标签),这将是看到的未绑定字段。
解决方案
对于这种情况,我将假设您的文本框被称为Welcome
. 你可能需要使用这样的东西:
Set rs = CurrentDb.OpenRecordset("Employees", dbOpenSnapshot, dbReadOnly)
rs.FindFirst "UserName='" & Me.TxtUsername & "'"
If rs.NoMatch Then
Me.LblWronguser.Visible = True
Me.TxtUsername.SetFocus
Exit Sub
Else
Me.Welcome = rs!UserName
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("EmployeeType") = rs!EmployeeType_ID.Value
DoCmd.OpenForm "Home"
DoCmd.Close acForm, Me.Name
请注意,这只会将用户名应用于Welcome
文本框。如果需要名称,则需要以不同的方式引用此类列,例如Me.Welcome = rs!FirstName
或其他内容。此外,由于存在密码验证,您可能需要重新构建内容,以便仅在正确传递密码部分后才会填充名称。
推荐阅读
- javascript - 在javascript中添加乘法时间表的起点和终点
- tensorflow - 带有 NCE 或采样 softmax 的 TensorFlow 多标签
- gitlab - 由于无法从远程存储库中读取,Gitlab 推送第一个项目失败
- java - 依赖注入不适用于@ClientEndpoint java
- html - 使用指定模板从 html 源文件中提取数据
- ionic-framework - 如何解决 Azure DevOps Ionic 管道构建错误?
- eclipse - 更改 Eclipse CDT 设置的选项卡背景颜色
- c++ - 以地图为参数的函数不起作用
- aws-lambda - 使用 python 从 dynamodb 获取项目
- python - Python 格式前导零和千位逗号