使用VBA验证用户密码输入 [英] Validate User password entry using VBA

查看:476
本文介绍了使用VBA验证用户密码输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计们,提前感谢您的时间。


我是Access VB的新手,所以你必须忍受我。

我有一张桌子tblUser

(userID {PK},userType,userPassword,userName,Status,numberOfJobs,skillID)


和我有一个访问表单(frmLogin),其中包含一个登录按钮


我试图从两个文本框(txtUN,textPW)读取表单并搜索联合国的tblUser (从文本框中),然后将密码与userPassword进行比较,如果它们是正确的,则根据userType导航到另外两种形式之一。


现在我的代码理论很好,但它只是试图让这个连接到这些线程中从未提到过的数据库......现在我想知道你是否愿意在这里发布一些代码来帮助我,我试过,但没有成功,用查询(搜索)或= Dlookup()填充记录集,我不能枯萎工作。


是否有人能够发布所有代码,而不仅仅是适当的行,因为我觉得我缺少了一些整体,但却非常简单,如CurrentDB = DAO.Database等等,所以假设我还没有全局,我只是看着

Hi Folks, thanks in advance for your time.

I''m pretty new to Access VB so you will have to bear with me.

I have a table tblUser
(userID{PK}, userType, userPassword, userName, Status, numberOfJobs, skillID)

and I have an access form (frmLogin) which contains a Login button

and I am trying to get the form to read in from two text boxes (txtUN, textPW) and search tblUser for the UN (from the textbox), then compare the password to the userPassword, and if they are correct, navigate to one of two other forms depending on the userType.

Now my code theory is fine, but it is just trying to get this to connect to the DB which is never mentioned in these threads... Now I was wondering if one of ou would be kind enough to post some code here to help me, I have tried, unsuccessfully, to populate a recordset with a query (to search) or the =Dlookup() and I can''t get wither to work.

Would someone be able to post ALL the code, not just appropriate lines, as I feel I am missing something integeral, yet insanely simple like CurrentDB=DAO.Database or something, so assume I have no globals as yet and am just looking at

展开 | 选择 | Wrap | 行号

推荐答案

简单方法是使用DLOOKUP(fieldname,tablename,where condition)函数如:

IF IsNull(DLOOKUP(" password,) ; tblMembers" ,MemberName = &安培; chr(34)& me.txtMembername" chr(34)))然后

''找不到

msgbox"无效的会员名称"

end sub

否则

如果DLOOKUP(密码,tblMembers,MemberName ="& chr(34)& me.txtMembername" chr(34))<> ; Me.txtPassword然后

''错误的密码

msgbox"错误的密码"

end sub

else

''确定

endif

endif


chr(34)用于中和报价像O''Neily这样的会员名。


得到这个想法?


Nic; o)
The easy way will be to use the DLOOKUP("fieldname","tablename","where condition") function like:

IF IsNull(DLOOKUP("password","tblMembers","MemberName =" & chr(34) & me.txtMembername " chr(34))) then
'' not found
msgbox "Invalid Membername"
end sub
else
if DLOOKUP("password","tblMembers","MemberName=" & chr(34) & me.txtMembername " chr(34)) <> Me.txtPassword then
'' wrong password
msgbox "Wrong password"
end sub
else
'' OK
endif
endif

The chr(34) is used to neutralize quotes in membernames like O''Neily.

Getting the idea ?

Nic;o)


我一直得到一个


编译错误:


预期:列表分隔符或)


错误,当我尝试的时候我一直在弄清楚。


任何想法?


代码只是改为适合我的表/值

I keep getting a

"Compile error:

Expected: List separator or )"

Error, something I kept getting myself when I tried.

Any Ideas?

The code has only been changed to suit my tables/values

展开 | 选择 | Wrap | 行号


注意:如果您(真的)感兴趣,可以在这里找到.mdb:

http://www.cmdclan.co.uk/Temp/jr_system.mdb


这是我们正在进行的frmLogin。


Mark
NB: If you are (really) interested the .mdb can be found here:

http://www.cmdclan.co.uk/Temp/jr_system.mdb

And it is the frmLogin we are working on.

Mark


这篇关于使用VBA验证用户密码输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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