Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code not checking all records.

Status
Not open for further replies.

Krash878

Programmer
May 8, 2001
172
US
I am building a password module.

I have a table called pass and on a form I have 2 text boxes. nameenter and passenter.

The form is generic and will open another generic form.

My problem is the code is not looking at the entire pass table for the user name and password. My logic may be off but here is what I have.

Dim pwd As String
Dim nam As String
pwd = DLookup("password", "Pass")
nam = DLookup("username", "Pass")
If nam <> Me.nameenter Or IsNull(Me.nameenter) = True Then
MsgBox &quot;You have entered an invalid User ID&quot;
Else
If pwd <> Me.passenter Or IsNull(Me.passenter) = True Then
MsgBox &quot;You have entered an invalid password.&quot;
Else

Dim stDocName As String
Dim stLinkCriteria As String
stDocName = &quot;Data&quot;
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
End If

Thanks in advance

Kenny
 
You need to enter Criteria in your Dlookup statement otherwise the Dlookup only returns the 1st record it finds.

You should only use 1 dlookup to find 1 record.

pwd = DLookup(&quot;password&quot;, &quot;Pass&quot;,&quot;Username = '&quot; & me!nameenter & &quot;'&quot;)
Maq B-)
<insert witty signature here>
 
Ok with the code like this:

Dim pwd As String
pwd = DLookup(&quot;password&quot;, &quot;Pass&quot;, &quot;Username = '&quot; & Me!nameenter & &quot;'&quot;)
If pwd <> Me.passenter Then
MsgBox &quot;You have entered an invalid password.&quot;
Else
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = &quot;Data&quot;
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If

If I enter a Valid User Id and invalid password my MsgBox pops up, But if I enter an invalid User Id the error is

Invalid Use of Null

How do I get rid of that?

thanks
Kenny
 
VB does not ever allow strings to be set = to Null, Since your variable pwd is a string you must set it equal to something other than Null (which is what the Dlookup command returns if it can't find a record).

This is a common programmer's trick to fix the problem.

Dim pwd As String
pwd = DLookup(&quot;password&quot;, &quot;Pass&quot;, &quot;Username = '&quot; & Me!nameenter & &quot;'&quot;) & &quot;&quot;
Maq B-)
<insert witty signature here>
 
ok That works but now if I just click the submit command button it runs through it with both text boxes blank.

hehe

Kenny
 
sorry I did not clarify.

Now that it has the zero length string it excecutes the rest of the code and opens the next form with out a password or a user ID.

 
LOL, so much for the security when your users notice that loophole.

I assume you know how to check for pwd = &quot;&quot; and trap the users. Maq B-)
<insert witty signature here>
 
nope I got it. I removed that IsNull check from the passenter part. It works and the code looks like this.

Thank you for your help
Kenny

Dim pwd As String
pwd = DLookup(&quot;password&quot;, &quot;Pass&quot;, &quot;Username = '&quot; & Me!nameenter & &quot;'&quot;) & &quot;&quot;

If pwd <> Me.passenter Or IsNull(Me.passenter) = True Then
MsgBox &quot;You have entered an invalid password.&quot;
Else
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = &quot;Data&quot;
DoCmd.Close
DoCmd.OpenForm stDocName, , , stLinkCriteria
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top