String and Dlookup

D

DubboPete

Hi all,

Have tried variations on this, but keep getting Error 2428. Anyone know
what's wrong with these lines of code, and why I get error 2428?

I'm trying to compare the password for a UserID (stored in TblUsers) to a
text string they enter in field [text4].

<snip>

Dim StrPwd As String
StrPwd = DLookup("password", TblUsers, "[UserID] =
[Forms]![FrmLogin]![Combo0]")

If Me.Text4 = StrPwd Then
DoCmd.OpenForm "FrmBOMCreate"
Else
et cetera, et cetera, et cetera......

</snip>


Combo0 returns a numeric value, to try and match to [tblusers].[userid].
Password field in TblUsers is text.

Hmmmm....
17th Century Goat-Herder
 
S

Shane S via AccessMonster.com

Hey Pete,

If 'UserID' is a number try:
StrPwd = DLookup("password", TblUsers, "[UserID] = " & [Forms]![FrmLogin]!
[Combo0])

If it's a text try:
StrPwd = DLookup("password", TblUsers, "[UserID] = '" & [Forms]![FrmLogin]!
[Combo0] & "'")
'I added 1 space so you could see what's happening- ' "
" ' "

HTH,
Shane
Hi all,

Have tried variations on this, but keep getting Error 2428. Anyone know
what's wrong with these lines of code, and why I get error 2428?

I'm trying to compare the password for a UserID (stored in TblUsers) to a
text string they enter in field [text4].

<snip>

Dim StrPwd As String
StrPwd = DLookup("password", TblUsers, "[UserID] =
[Forms]![FrmLogin]![Combo0]")

If Me.Text4 = StrPwd Then
DoCmd.OpenForm "FrmBOMCreate"
Else
et cetera, et cetera, et cetera......

</snip>

Combo0 returns a numeric value, to try and match to [tblusers].[userid].
Password field in TblUsers is text.

Hmmmm....
17th Century Goat-Herder
 
G

Guest

I suggest always bracketing fields and tblUsers without quotes makes Access
think tblUsers is a variable that will contain the name of the table.

StrPwd = DLookup("[password]", "TblUsers", "[UserID] = " & [Forms]![FrmLogin]!
[Combo0])

Shane S via AccessMonster.com said:
Hey Pete,

If 'UserID' is a number try:
StrPwd = DLookup("password", TblUsers, "[UserID] = " & [Forms]![FrmLogin]!
[Combo0])

If it's a text try:
StrPwd = DLookup("password", TblUsers, "[UserID] = '" & [Forms]![FrmLogin]!
[Combo0] & "'")
'I added 1 space so you could see what's happening- ' "
" ' "

HTH,
Shane
Hi all,

Have tried variations on this, but keep getting Error 2428. Anyone know
what's wrong with these lines of code, and why I get error 2428?

I'm trying to compare the password for a UserID (stored in TblUsers) to a
text string they enter in field [text4].

<snip>

Dim StrPwd As String
StrPwd = DLookup("password", TblUsers, "[UserID] =
[Forms]![FrmLogin]![Combo0]")

If Me.Text4 = StrPwd Then
DoCmd.OpenForm "FrmBOMCreate"
Else
et cetera, et cetera, et cetera......

</snip>

Combo0 returns a numeric value, to try and match to [tblusers].[userid].
Password field in TblUsers is text.

Hmmmm....
17th Century Goat-Herder
 
D

DubboPete

Heya Klatuu,

That little tip worked, where Shane's didn't. Thanks mate. Now to the
next challenge!

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top