【问题标题】:Set the Caption of label to Username将标签的标题设置为用户名
【发布时间】:2021-03-23 20:41:45
【问题描述】:

我正在制作一个 Access 数据库并具有安全登录功能。我想使用在标签或其他控件中输入的用户名作为“登录为”功能。

如何引用不是我的登录表单的其他表单?

我想将 ID 或用户名附加到表单 UserViewForm 中的标签 66。

Private Sub Command1_Click()

Dim User As String
Dim UserLevel As Integer
Dim TempPass As String
Dim ID As Integer
Dim UserName As String
Dim TempID As String

If IsNull(Me.TxtUserName) Then
 MsgBox "Please enter UserName", vbInformation, "Username required"
 Me.TxtUserName.SetFocus
ElseIf IsNull(Me.TxtPassword) Then
 MsgBox "Please enter Password", vbInformation, "Password required"
 Me.TxtPassword.SetFocus
Else
 If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.TxtUserName.Value & "' And UserPassword = '" & Me.TxtPassword.Value & "'"))) Then
 MsgBox "Invalid Username or Password!"
 Else
 TempID = Me.TxtUserName.Value
 UserName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.TxtUserName.Value & "'")
 UserLevel = DLookup("[UserType]", "tblUser", "[UserLogin] = '" & Me.TxtUserName.Value & "'")
 TempPass = DLookup("[UserPassword]", "tblUser", "[UserLogin] = '" & Me.TxtUserName.Value & "'")
 UserLogin = DLookup("[UserLogin]", "tblUser", "[UserLogin] = '" & Me.TxtUserName.Value & "'")
 DoCmd.Close
 If (TempPass = "password") Then
 MsgBox "Please change Password", vbInformation, "New password required"
 DoCmd.OpenForm "frmUserinfo", , , "[UserLogin] = " & UserLogin
 Else
 'open different form according to user level
 If UserLevel = 1 Then ' for admin
 DoCmd.OpenForm "UserViewForm"
 'Else
 'DoCmd.OpenForm "Ne"
 End If
 End If
 End If
End If

Forms!UserViewFrom.Label66 = TempID

End Sub

这是为了用户体验。

【问题讨论】:

    标签: vba ms-access-2010


    【解决方案1】:

    对于标签,您需要设置Caption 属性。

    Forms!UserViewFrom.Label66.Caption = TempID
    

    另请注意,您不应以明文形式存储密码,也不应使用未经处理的用户输入来构建 SQL 命令 - 查找 SQL 注入。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      • 2016-07-24
      • 1970-01-01
      相关资源
      最近更新 更多