$ C $下使用DLookup的登录用户名和密码 [英] code for DLookup for login username and password

查看:541
本文介绍了$ C $下使用DLookup的登录用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个登录形式,但我不知道如何获得或证实什么,我输入了我的用户名和密码文本框是在我的登录按钮,使用使用DLookup我的表。

下面是我目前的code:

 昏暗u,如变异
昏暗数p作为变异
昏暗的犬作为字符串
昏暗的INP作为字符串

U =使用DLookup(cusername,tbl_users,inuser.Value)
p值=使用DLookup(cpassword,tbl_users,inpass.Value)

犬= inuser.Value
INP = inpass.Value

如果犬= u和INP = P然后
DoCmd.OpenFormfrm_userlog
MSGBOX欢迎和放大器; TUSER和放大器; !

elseif的ISNULL(Me.inuser.Value)和inpass.Value = 1,则
MSGBOX你必须输入一个用户名

elseif的ISNULL(Me.inpass.Value)和inuser.Value = 1,则
MSGBOX你必须输入密码。

elseif的ISNULL(Me.inuser.Value)和ISNULL(Me.inpass.Value)然后
MSGBOX你必须输入用户名和密码

其他
MSGBOX您输入的用户名或密码无效
    结束如果
结束小组
 

解决方案

第三的使用DLookup 的说法,的标准的,是一个可选的字符串EX pression这是一个类似的其中一个SQL EX pression条款,无字其中的。

在你的,你似乎是想给它命名为 inuser 控件的值。但是你实际上是通过包含文本的inuser.Value字符串的。

 使用DLookup(cusername,tbl_users,inuser.Value)
 

但是,这不会给你想要的,即使你删除引号什么。

如果你想查找 cusername tbl_users ,其中一些领域(也许 USER_ID )匹配 inuser.Value ...

 使用DLookup(cusername,tbl_users,USER_ID =&放大器; inuser.Value)
 

如果该字段, USER_ID ,是文本而不是数字数据类型,打造报价到的标准的字符串...

 使用DLookup(cusername,tbl_users,user_ID的='&放大器; inuser.Value&安培;')
 

它看起来像你对我有同一类型的问题使用DLookup(cpassword,...),所以如果我拿到了第一个权利,使类似的变化在那里。

您可以在说明找到使用DLookup 了解更多信息的使用DLookup()使用率,示例,和Access 2000中故障排除。虽然这是一个古老的文章,一切都仍然适用于近期的Access版本AFAICT。

I want to make a log-in form, but I don't know how to get or confirm that what I typed in my Username and password textbox is in my table using DLookup in my log-in button.

Here's my current code:

Dim u As Variant
Dim p As Variant
Dim inu As String
Dim inp As String

u = DLookup("cusername", "tbl_users", "inuser.Value")
p = DLookup("cpassword", "tbl_users", "inpass.Value")

inu = inuser.Value
inp = inpass.Value

If inu = u And inp = p Then
DoCmd.OpenForm "frm_userlog"
MsgBox "Welcome " & tuser & "!"

ElseIf IsNull(Me.inuser.Value) And inpass.Value = 1 Then
MsgBox "You must input a username"

ElseIf IsNull(Me.inpass.Value) And inuser.Value = 1 Then
MsgBox "you must input a password"

ElseIf IsNull(Me.inuser.Value) And IsNull(Me.inpass.Value) Then
MsgBox "you must input a username and password"

Else
MsgBox "The username or password you entered is invalid"
    End If
End Sub

解决方案

The third DLookup argument, criteria, is an optional string expression which is similar to a "WHERE clause in an SQL expression, without the word WHERE".

In yours, you seem to be trying to give it the value of a control named inuser. However you're actually passing a string which contains the text "inuser.Value".

DLookup("cusername", "tbl_users", "inuser.Value")

But that won't give you what you want even if you remove the quotes.

If you want to look up cusername from tbl_users where some field (perhaps user_id) matches inuser.Value ...

DLookup("cusername", "tbl_users", "user_id = " & inuser.Value)

If that field, user_id, is text rather than numeric data type, build quotes into the criteria string ...

DLookup("cusername", "tbl_users", "user_id = '" & inuser.Value & "'")

It looks to me like you have the same type of issue with DLookup("cpassword", ...), so if I got the first one right, make a similar change there.

You can find more information about DLookup at Description of DLookup() usage, examples, and troubleshooting in Access 2000. Although that's an old article, everything still applies to recent Access versions AFAICT.

这篇关于$ C $下使用DLookup的登录用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆