简体   繁体   English

使用宏在 Microsoft Access 中创建登录表单,不使用 VBA。

[英]Creating a login form in Microsoft Access using macros, without VBA.

I've looked around for ages and I haven't found an answer to my problem so I was hoping someone here could help me.我环顾四周很久了,但我还没有找到问题的答案,所以我希望这里有人可以帮助我。

I am creating a system using Microsoft Access where I have a members table containing a username and password and various other fields such as date of birth, etc.我正在使用 Microsoft Access 创建一个系统,其中我有一个包含用户名和密码以及各种其他字段(例如出生日期等)的成员表。

I want to create a form where users can enter a username and password.我想创建一个表单,用户可以在其中输入用户名和密码。 By clicking a button on this form, these details will then be checked against the usernames and passwords in the members table.通过单击此表单上的按钮,这些详细信息将根据成员表中的用户名和密码进行检查。 If the details match, a message will be displayed saying they have logged in. If the details are not found in the table, a message saying the details are incorrect will show.如果详细信息匹配,将显示一条消息,说明他们已登录。如果在表中未找到详细信息,将显示一条消息,说明详细信息不正确。

How can I do this without using VBA?在不使用 VBA 的情况下如何做到这一点?

I have started by creating a form called loginform with two text boxes loginusername and loginpassword .我首先创建了一个名为loginform的表单,其中包含两个文本框loginusernameloginpassword

Where should I go from here?我应该从这里到哪里 go?

The VBA solution shouldn't be that complicated. VBA 解决方案不应该那么复杂。 A quick and dirty solution:一个快速而肮脏的解决方案:

Dim Result as Variant

Result=Dlookup("Password","tblMembers","UserName='" & nz(loginusername.value,"") & "'")
If nz(Result,"")<>nz([login password].value,"") Then
  MsgBox "Invalid password"
Else
  MsgBox "Password correct"
End If
'set the variables
Dim UN As String
Dim PW As String
Dim user, pass As Boolean
'make sure none of the fields are null, or blank
UN = Text
PW = Text
If IsNull(Username) Then
MsgBox "You must enter a username."
Username.SetFocus
Else
'assign true to user
user = True
End If
If IsNull(Password) Then
MsgBox "You must enter a password."
Password.SetFocus
Else
pass = True
End If
If user = True And pass = True Then
UN = DLookup("[Username]", "LoginTable", "[Username]= '" & Me.Username & "'")
PW = DLookup("[Password]", "LoginTable", "[Password] = '" & Me.Password & "'")
End If
If Me.DummyUser = Me.Username And Me.DummyPass = Me.Password Then
MsgBox "Access granted."
Else
MsgBox "Access denied."
End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM