Ms access 在MS ACCESS中,是否可以执行以下操作:DoCmd.OpenForm“;德鲁库普……”;?
MS Access 2013 我有一个tblUser表,其中包含以下数据(用户名/密码/StartForm) 我有一个登录系统,用户在其中输入名为txtLogin的表单字段作为用户名 用户名和密码匹配后,我需要为每个用户打开一个特定的表单(取决于他在公司的职能)。 我有这个代码,但无法解决问题Ms access 在MS ACCESS中,是否可以执行以下操作:DoCmd.OpenForm“;德鲁库普……”;?,ms-access,vba,Ms Access,Vba,MS Access 2013 我有一个tblUser表,其中包含以下数据(用户名/密码/StartForm) 我有一个登录系统,用户在其中输入名为txtLogin的表单字段作为用户名 用户名和密码匹配后,我需要为每个用户打开一个特定的表单(取决于他在公司的职能)。 我有这个代码,但无法解决问题 DoCmd.OpenForm DLookup("StartForm", "tblUser","[UserName]='" & txtLogin & "';") 我只是开始编程,我想学习,
DoCmd.OpenForm DLookup("StartForm", "tblUser","[UserName]='" & txtLogin & "';")
我只是开始编程,我想学习,而不是复制/粘贴代码,所以我非常感谢你能给我一个简单的解释
谢谢的第一个参数是表单名称。要将窗体打开到特定参数,需要使用
Private Sub cmdLogin_Click()
Dim rst As Recordset
Dim nomeUsuario As String
If IsNull(txtLogin) Or IsNull(txtSenha) Then
MsgBox "Preencha o login e senha"
Exit Sub
End If
nomeUsuario = txtLogin
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblUser WHERE UserName = '" & txtLogin & "' AND Password = '" & txtSenha & "';")
If rst.RecordCount = 1 Then
bcansafelyclose = True
DoCmd.Close
Dim nomeForm As String
nomeForm = DLookup("Start", "tblUser", "UserName = '" & nomeUsuario & "'")
DoCmd.OpenForm nomeForm
Else
MsgBox "Login ou senha incorretos"
bcansafelyclose = False
End If
rst.Close
End Sub
第四个参数,即WhereCondition
此处不需要使用Dlookup
功能。它用于从单个记录返回单个列,其中源列是第一个参数,源表是第二个参数。它通过搜索条件(第三个参数)知道要获取什么记录
按照这种设置方式,您要求DoCmd.OpenForm
以[您的DLookup调用结果]
的名称打开一个表单,而不应用任何筛选器
你想要的更像这样
DoCmd.OpenForm NameOfYourUserForm, acNormal, , "[UserName]='" & txtLogin & "'"
要设置的第一个参数是表单名称。要将窗体打开到特定参数,需要使用
第四个参数,即WhereCondition
此处不需要使用Dlookup
功能。它用于从单个记录返回单个列,其中源列是第一个参数,源表是第二个参数。它通过搜索条件(第三个参数)知道要获取什么记录
按照这种设置方式,您要求DoCmd.OpenForm
以[您的DLookup调用结果]
的名称打开一个表单,而不应用任何筛选器
你想要的更像这样
DoCmd.OpenForm NameOfYourUserForm, acNormal, , "[UserName]='" & txtLogin & "'"
我能够解决以下问题。 我为我想要调用的表单(nomeForm)创建了一个变量,并使用Dlookup为每个用户找到合适的表单 多谢各位
Private Sub cmdLogin_Click()
Dim rst As Recordset
Dim nomeUsuario As String
If IsNull(txtLogin) Or IsNull(txtSenha) Then
MsgBox "Preencha o login e senha"
Exit Sub
End If
nomeUsuario = txtLogin
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblUser WHERE UserName = '" & txtLogin & "' AND Password = '" & txtSenha & "';")
If rst.RecordCount = 1 Then
bcansafelyclose = True
DoCmd.Close
Dim nomeForm As String
nomeForm = DLookup("Start", "tblUser", "UserName = '" & nomeUsuario & "'")
DoCmd.OpenForm nomeForm
Else
MsgBox "Login ou senha incorretos"
bcansafelyclose = False
End If
rst.Close
End Sub
我能够解决以下问题。 我为我想要调用的表单(nomeForm)创建了一个变量,并使用Dlookup为每个用户找到合适的表单 多谢各位
Private Sub cmdLogin_Click()
Dim rst As Recordset
Dim nomeUsuario As String
If IsNull(txtLogin) Or IsNull(txtSenha) Then
MsgBox "Preencha o login e senha"
Exit Sub
End If
nomeUsuario = txtLogin
Set rst = CurrentDb.OpenRecordset("SELECT * FROM tblUser WHERE UserName = '" & txtLogin & "' AND Password = '" & txtSenha & "';")
If rst.RecordCount = 1 Then
bcansafelyclose = True
DoCmd.Close
Dim nomeForm As String
nomeForm = DLookup("Start", "tblUser", "UserName = '" & nomeUsuario & "'")
DoCmd.OpenForm nomeForm
Else
MsgBox "Login ou senha incorretos"
bcansafelyclose = False
End If
rst.Close
End Sub
你好你的回答很有启发性,我很感激。不过,我最终还是用了另一种方法。谢谢你好。你的回答很有启发性,我很感激。不过,我最终还是用了另一种方法。谢谢你,你好,HansUp。对我想出了一个答案。谢谢你,你好,HansUp。对我想出了一个答案。非常感谢。