Sql Microsoft Access-从用户ID显示登录用户的名称

Sql Microsoft Access-从用户ID显示登录用户的名称,sql,ms-access,vba,ms-access-2010,ms-access-2013,Sql,Ms Access,Vba,Ms Access 2010,Ms Access 2013,我有一个Access数据库,它有一个简单的登录系统,由一个下拉菜单(组合菜单)组成,用于选择用户名、密码字段和用户表 在users表中,我存储所有用户的用户名、密码和名字。我已经设法让我的登录表单工作,但我希望在下一个表单的文本框中显示用户的名字 我已经成功地获取了用户的ID号,并将其显示在文本框中,但是我无法获取用户的名字 有人知道在文本框中显示用户名字的简单方法吗?请记住,我有几个表单,希望在其中显示用户的名字 谢谢因为您的描述中说您使用的是组合框,我相信行源将是 SELECT ID, us

我有一个Access数据库,它有一个简单的登录系统,由一个下拉菜单(组合菜单)组成,用于选择用户名、密码字段和用户表

在users表中,我存储所有用户的用户名、密码和名字。我已经设法让我的登录表单工作,但我希望在下一个表单的文本框中显示用户的名字

我已经成功地获取了用户的ID号,并将其显示在文本框中,但是我无法获取用户的名字

有人知道在文本框中显示用户名字的简单方法吗?请记住,我有几个表单,希望在其中显示用户的名字


谢谢

因为您的描述中说您使用的是组合框,我相信行源将是

SELECT ID, userNameField
FROM EmpAuth;
组合框属性为绑定列-1,列计数-2,列宽-0cm;2.5厘米(类似于此,但肯定是0厘米)。现在,您只需做以下更改,RowSource:

SELECT ID, userNameField, firstNameField
FROM EmpAuth;
组合框属性是绑定列-1,列计数-3,列宽-0cm;2.5厘米**;0厘米**

然后,您可以简单地使用OpenArgs方法,在这里您可以传递组合框第3列。像

If Me.password.Value = DLookup("password", "EmpAuth", _
        "[ID]=" & Me.username.Value) Then

    ID = Me.username.Value

    DoCmd.OpenForm "POSMenu", OpenArgs:=Me.username.Column(2) 
    'Close logon form and open splash screen
    DoCmd.Close acForm, "AuthenticationService", acSaveNo


Else
  MsgBox.............
最后,在第二个表单的On Load事件中,您可以使用

Private Sub Form_Load()
    If Len(Me.OpenArgs & vbNullString) > 0 Then _
        Me.yourTextBoxName = Me.OpenArgs
End Sub

希望这能有所帮助。

正如您的描述所说,您正在使用一个组合框,我相信RowSource会很有用

SELECT ID, userNameField
FROM EmpAuth;
组合框属性为绑定列-1,列计数-2,列宽-0cm;2.5厘米(类似于此,但肯定是0厘米)。现在,您只需做以下更改,RowSource:

SELECT ID, userNameField, firstNameField
FROM EmpAuth;
组合框属性是绑定列-1,列计数-3,列宽-0cm;2.5厘米**;0厘米**

然后,您可以简单地使用OpenArgs方法,在这里您可以传递组合框第3列。像

If Me.password.Value = DLookup("password", "EmpAuth", _
        "[ID]=" & Me.username.Value) Then

    ID = Me.username.Value

    DoCmd.OpenForm "POSMenu", OpenArgs:=Me.username.Column(2) 
    'Close logon form and open splash screen
    DoCmd.Close acForm, "AuthenticationService", acSaveNo


Else
  MsgBox.............
最后,在第二个表单的On Load事件中,您可以使用

Private Sub Form_Load()
    If Len(Me.OpenArgs & vbNullString) > 0 Then _
        Me.yourTextBoxName = Me.OpenArgs
End Sub

希望这能有所帮助。

正如您的描述所说,您正在使用一个组合框,我相信RowSource会很有用

SELECT ID, userNameField
FROM EmpAuth;
组合框属性为绑定列-1,列计数-2,列宽-0cm;2.5厘米(类似于此,但肯定是0厘米)。现在,您只需做以下更改,RowSource:

SELECT ID, userNameField, firstNameField
FROM EmpAuth;
组合框属性是绑定列-1,列计数-3,列宽-0cm;2.5厘米**;0厘米**

然后,您可以简单地使用OpenArgs方法,在这里您可以传递组合框第3列。像

If Me.password.Value = DLookup("password", "EmpAuth", _
        "[ID]=" & Me.username.Value) Then

    ID = Me.username.Value

    DoCmd.OpenForm "POSMenu", OpenArgs:=Me.username.Column(2) 
    'Close logon form and open splash screen
    DoCmd.Close acForm, "AuthenticationService", acSaveNo


Else
  MsgBox.............
最后,在第二个表单的On Load事件中,您可以使用

Private Sub Form_Load()
    If Len(Me.OpenArgs & vbNullString) > 0 Then _
        Me.yourTextBoxName = Me.OpenArgs
End Sub

希望这能有所帮助。

正如您的描述所说,您正在使用一个组合框,我相信RowSource会很有用

SELECT ID, userNameField
FROM EmpAuth;
组合框属性为绑定列-1,列计数-2,列宽-0cm;2.5厘米(类似于此,但肯定是0厘米)。现在,您只需做以下更改,RowSource:

SELECT ID, userNameField, firstNameField
FROM EmpAuth;
组合框属性是绑定列-1,列计数-3,列宽-0cm;2.5厘米**;0厘米**

然后,您可以简单地使用OpenArgs方法,在这里您可以传递组合框第3列。像

If Me.password.Value = DLookup("password", "EmpAuth", _
        "[ID]=" & Me.username.Value) Then

    ID = Me.username.Value

    DoCmd.OpenForm "POSMenu", OpenArgs:=Me.username.Column(2) 
    'Close logon form and open splash screen
    DoCmd.Close acForm, "AuthenticationService", acSaveNo


Else
  MsgBox.............
最后,在第二个表单的On Load事件中,您可以使用

Private Sub Form_Load()
    If Len(Me.OpenArgs & vbNullString) > 0 Then _
        Me.yourTextBoxName = Me.OpenArgs
End Sub

希望这有帮助。

如果你要用多种形式使用用户名信息,也许你可以考虑使用会话变量来访问信息。这比将其作为参数从一个对象传递到另一个对象要简洁一些

'On the login page,upon confirming the login is correct,
'Initialise session variables
TempVars.RemoveAll 'Destroy any previous Session

'Retrieve the username from the table
UserName = Dlookup("Usernamecol","UsersTable","UserID=" & SelectedUSerID
'Load the retrieved username into a global session variable
TempVars.Add "GlbUserName", UserName
'Use this whenever you want to show the user name
LoggedInUser = TempVars![GlbUserName]
Me.txtUserName = LoggedInUser
'or
Me.lblUserName.caption = LoggedInUser

如果您要用多种形式使用用户名信息,也许您可以考虑使用会话变量来访问信息。这比将其作为参数从一个对象传递到另一个对象要简洁一些

'On the login page,upon confirming the login is correct,
'Initialise session variables
TempVars.RemoveAll 'Destroy any previous Session

'Retrieve the username from the table
UserName = Dlookup("Usernamecol","UsersTable","UserID=" & SelectedUSerID
'Load the retrieved username into a global session variable
TempVars.Add "GlbUserName", UserName
'Use this whenever you want to show the user name
LoggedInUser = TempVars![GlbUserName]
Me.txtUserName = LoggedInUser
'or
Me.lblUserName.caption = LoggedInUser

如果您要用多种形式使用用户名信息,也许您可以考虑使用会话变量来访问信息。这比将其作为参数从一个对象传递到另一个对象要简洁一些

'On the login page,upon confirming the login is correct,
'Initialise session variables
TempVars.RemoveAll 'Destroy any previous Session

'Retrieve the username from the table
UserName = Dlookup("Usernamecol","UsersTable","UserID=" & SelectedUSerID
'Load the retrieved username into a global session variable
TempVars.Add "GlbUserName", UserName
'Use this whenever you want to show the user name
LoggedInUser = TempVars![GlbUserName]
Me.txtUserName = LoggedInUser
'or
Me.lblUserName.caption = LoggedInUser

如果您要用多种形式使用用户名信息,也许您可以考虑使用会话变量来访问信息。这比将其作为参数从一个对象传递到另一个对象要简洁一些

'On the login page,upon confirming the login is correct,
'Initialise session variables
TempVars.RemoveAll 'Destroy any previous Session

'Retrieve the username from the table
UserName = Dlookup("Usernamecol","UsersTable","UserID=" & SelectedUSerID
'Load the retrieved username into a global session variable
TempVars.Add "GlbUserName", UserName
'Use this whenever you want to show the user name
LoggedInUser = TempVars![GlbUserName]
Me.txtUserName = LoggedInUser
'or
Me.lblUserName.caption = LoggedInUser

您可以发布您的代码吗?声明一个全局变量,并在登录按钮上单击使用select查询对其赋值,并在其中传递userId以选择名字。在所有页面上放置标签,并在其上加载分配全局变量值。创建一个模块,然后像这样声明-全局FName您可以发布您的代码吗?声明一个全局变量,然后在登录按钮上单击分配值,使用select query并在其中传递userId以选择名字。在所有页面上放置标签,并在其上加载分配全局变量值。创建一个模块,然后像这样声明-全局FName您可以发布您的代码吗?声明一个全局变量,然后在登录按钮上单击分配值,使用select query并在其中传递userId以选择名字。在所有页面上放置标签,并在其上加载分配全局变量值。创建一个模块,然后像这样声明-全局FName您可以发布您的代码吗?声明一个全局变量,然后在登录按钮上单击分配值,使用select query并在其中传递userId以选择名字。在所有页面上放置标签并在加载时为其分配全局变量值。创建一个模块,然后像这样声明-全局fname