Vba 如何转到特定用户';s在登录表单中输入用户名/密码后的记录

Vba 如何转到特定用户';s在登录表单中输入用户名/密码后的记录,vba,Vba,我正在尝试为一个大学系统创建一个登录页面,如果用户已经注册了他们的详细信息,那么我就无法让数据库打开用户的特定表单。e、 g.下面的代码是“编辑配置文件”按钮的代码,因此它需要打开特定用户的记录,而不是当前的“docmd.openform”StudentF。有什么想法吗 Private Sub EditProfileLF_Click() 'Dimensions Dim correctpassword As String Dim registereduser As String Dim stud

我正在尝试为一个大学系统创建一个登录页面,如果用户已经注册了他们的详细信息,那么我就无法让数据库打开用户的特定表单。e、 g.下面的代码是“编辑配置文件”按钮的代码,因此它需要打开特定用户的记录,而不是当前的“docmd.openform”StudentF。有什么想法吗

Private Sub EditProfileLF_Click()
'Dimensions

Dim correctpassword As String
Dim registereduser As String
Dim studentnumberLen As Integer

'Trims and Ucase
Trim (StudentPasswordLF)
Trim (StudentNumberLF)
UCase (StudentNumberLF)

'No Student Number
If IsNull(StudentNumberLF) Then
MsgBox "Please Enter Your Student Number", vbOKOnly, "Student Number Required"
Exit Sub
End If

'No Password
If IsNull(StudentPasswordLF) Then
MsgBox "Please Enter Your Password", vbOKOnly, "Password Required"
Exit Sub
End If

'Invalid Student Number
studentnumberLen = Len(StudentNumberLF)

If studentnumberLen < 7 Or studentnumberLen > 7 Or IsNumeric(Left(StudentNumberLF, 1)) Or Not (IsNumeric(Right(StudentNumberLF, 6))) Then
MsgBox "Please Enter a Valid Student Number, See FAQ for Help", vbOKOnly, "Invalid Student Number"
Exit Sub
End If

'Password Check
correctpassword = DLookup("[PasswordST]", "StudentT", "[StudentNumber]='" & Me.StudentNumberLF.Value & "'")


If StudentPasswordLF = correctpassword Then

DoCmd.OpenForm "StudentF"


Else

MsgBox "Incorrect Password, if you have forgotten your Password click 'Forgot Your Password'"

Exit Sub

End If
End Sub
Private子编辑档案lf_Click()
“尺寸
将密码设置为字符串
Dim registereduser作为字符串
Dim studentnumberLen为整数
“Trims和Ucase
修剪(学生密码LF)
修剪(学生编号LF)
UCase(学生编号LF)
“没有学生号
如果为空(StudentNumberLF),则
MsgBox“请输入您的学号”,vbOKOnly,“需要学号”
出口接头
如果结束
“没有密码
如果为null(StudentPasswordLF),则
MsgBox“请输入您的密码”,vbOKOnly,“需要密码”
出口接头
如果结束
'无效的学号
studentnumberLen=Len(StudentNumberLF)
如果studentnumberLen<7或studentnumberLen>7或是数字型(左(StudentNumberLF,1))或不是数字型(右(StudentNumberLF,6)),则
MsgBox“请输入有效的学号,请参阅常见问题解答以获取帮助”,vbOKOnly,“无效学号”
出口接头
如果结束
'密码检查
correctpassword=DLookup(“[PasswordST]”、“StudentT”、“[StudentNumber]=”&Me.StudentNumberLF.Value&“”)
如果StudentPasswordLF=correctpassword,则
DoCmd.OpenForm“StudentF”
其他的
MsgBox“密码不正确,如果您忘记了密码,请单击“忘记密码”
出口接头
如果结束
端接头

以下是使用过滤器的方法:

 DoCmd.OpenForm "StudentF", , , "[StudentNumber]='" & Me.StudentNumberLF.Value & "'"
在StudentF的表单属性中,确保“加载时筛选”设置为“是”

请注意,如果学生在数据库中没有记录,则DLookup将返回Null。最好使用DCount同时测试学生和密码,而不是从数据库中检索密码并在代码中进行比较

此外,这里有一个简单的方法来验证StudentNumber的正确格式:

  'Invalid Student Number
  With New RegExp                         
      .Pattern = "^[A-Z][0-9]{6}$"       ' one upper-case letter + six digits
      If Not .Test(StudentNumberLF) Then
          MsgBox "Please Enter a Valid Student Number, See FAQ for Help"
          Exit Sub
      End If
  End With

要启用RegExp,请转到工具>引用并选中“Microsoft VBScript正则表达式”“

希望这只是概念验证代码,因为以明文形式存储密码不是一个好主意。DoCmd.OpenForm将接受记录过滤器作为参数。使用该选项打开表单以获得正确的记录。看:我不能完全理解你链接的帖子。如果用户名登录框被称为“StudentNumber”,而我正试图从“StudentF”表单中打开一条记录,您能举例说明它是如何编码的吗?我被困在这个问题上有一段时间了