Who can help me with this code ???

C

Carola Hiddink

Hi everybody,

Based on a previous question by another sender, I have
programmed the below mentioned code. It works perfect,
except for one thing that I want to add, but cannot figure
out how to do that.

What I want is the following: I have a table that is
called Table1 that contains multiple data entrist names
and passwords. I want to be able to have a "simple"
security, by using a login form (FORM2) where the data
entrist has to type his/her name and his/her password.
This name and password then needs to be compared with the
name and password in Table1, and if the same, login is
accepted.
(The "real" security is done in a later stage, for now I
want to keep it simple !)

However, with the code I am having here, ANY of the
multiple passwords in the table if found to be correct,
not just the one that is mentioned behind the certain data
entrist name.

So: what do I need to add to the program to get that
done ? I am not really handy with programming Visual Basic
yet, but I think I'm well on the way of understanding...

Thanks a lot !!!
______________________________________________________

Private Sub Next_Click()
On Error GoTo Err_Next_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim found As String

found = Nz(DLookup("[PASSWD]", "[Table1]", "[PASSWD]
='" & Forms![Form2]![PASSWD] & "'"), "false")

If found <> "false" Then
MsgBox "Password is correct"

stDocName = "Subject number"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , ,
Me.Name
Me.Visible = False

Else

MsgBox "Password is incorrect"
DoCmd.Close

End If

Exit_Next_Click:
Exit Sub

Err_Next_Click:
MsgBox Err.Description
Resume Exit_Next_Click

End Sub
 
T

Ted Allen

Hi Carola,

You just need to revise the criteria in your Dlookup()
function to limit the domain such that it must match the
UserName and Password, not just the password. Try
something similar to the following, but replace UserName
with the actual form field name and table field name for
your situation.

found = Nz(DLookup("[PASSWD]", "[Table1]", "[PASSWD]
='" & Forms![Form2]![PASSWD] & "' AND [UserName] = '" &
Forms![Form2]![UserName] & "'"), "false")

HTH, Ted Allen
 
C

Carola Hiddink

Wow, if that's all, then it is quite easy ! Thanks, I will
try immediately, and get back to you if it doesn't work ;-)

Carola.
-----Original Message-----
Hi Carola,

You just need to revise the criteria in your Dlookup()
function to limit the domain such that it must match the
UserName and Password, not just the password. Try
something similar to the following, but replace UserName
with the actual form field name and table field name for
your situation.

found = Nz(DLookup("[PASSWD]", "[Table1]", "[PASSWD]
='" & Forms![Form2]![PASSWD] & "' AND [UserName] = '" &
Forms![Form2]![UserName] & "'"), "false")

HTH, Ted Allen
-----Original Message-----
Hi everybody,

Based on a previous question by another sender, I have
programmed the below mentioned code. It works perfect,
except for one thing that I want to add, but cannot figure
out how to do that.

What I want is the following: I have a table that is
called Table1 that contains multiple data entrist names
and passwords. I want to be able to have a "simple"
security, by using a login form (FORM2) where the data
entrist has to type his/her name and his/her password.
This name and password then needs to be compared with the
name and password in Table1, and if the same, login is
accepted.
(The "real" security is done in a later stage, for now I
want to keep it simple !)

However, with the code I am having here, ANY of the
multiple passwords in the table if found to be correct,
not just the one that is mentioned behind the certain data
entrist name.

So: what do I need to add to the program to get that
done ? I am not really handy with programming Visual Basic
yet, but I think I'm well on the way of understanding...

Thanks a lot !!!
______________________________________________________

Private Sub Next_Click()
On Error GoTo Err_Next_Click

Dim stDocName As String
Dim stLinkCriteria As String
Dim found As String

found = Nz(DLookup("[PASSWD]", "[Table1]", "[PASSWD]
='" & Forms![Form2]![PASSWD] & "'"), "false")

If found <> "false" Then
MsgBox "Password is correct"

stDocName = "Subject number"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , ,
Me.Name
Me.Visible = False

Else

MsgBox "Password is incorrect"
DoCmd.Close

End If

Exit_Next_Click:
Exit Sub

Err_Next_Click:
MsgBox Err.Description
Resume Exit_Next_Click

End Sub

.
.
 

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