Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2006, 09:02 PM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Having trouble with a recordset for Login screen

I'm setting up a login screen for an Access app I'm developing, that checks the user's Employee ID and Password against the database. However, when I run the code I get the following error:

"Item cannot be found in the collection corresponding to the requested name or ordinal."

I know what this error means, but the fields I am looking up are the exact ones that are in the database (EmployeeID and Password).

Here is the exact code:

Function Login(EmployeeID As String, Password As String) As Boolean
    Dim conn As ADODB.Connection
    Set conn = New ADODB.Connection

    conn.Open DbConnectionString

    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset

    With rs
        .LockType = adLockOptimistic
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .Open "SELECT FirstName, LastName, AccessCode FROM tblEmployees WHERE EmployeeID='" & EmployeeID & "'", conn
    End With

    If rs.BOF And rs.EOF Then
        Exit Function
    End If

    If EmployeeID = rs!EmployeeID And Password = rs!Password Then
        intAccessCode = rs!AccessCode
        strFirstName = rs!FirstName
        strLastName = rs!LastName

        Login = True
    Else
        Login = False
    End If
End Function

The line that's being flagged as the error is "If EmployeeID = rs!EmployeeID And Password = rs!Password Then"; with the debugger saying that the item cannot be found in the collection.

My table, tblEmployees, has the following fields:

EmployeeID - Text (Primary Key)
Password - Text
FirstName - Text
LastName - Text
AccessCode - Number

Any ideas on what's causing this problem?? I'm totally at a loss since the database fields exactly match the fields I'm trying to look up from the recordset

 
Old March 28th, 2006, 09:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

EmployeeID isn't included in the fields list of your SELECT statment, so it isn't included in your resultset (recordset object) either.

 
Old March 28th, 2006, 09:21 PM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

D'oh! Silly me. Thanks a lot!

 
Old March 28th, 2006, 09:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Your welcome. :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent help - Customized Windows login Screen Rehanrana Visual C++ 1 December 27th, 2007 03:48 AM
Login Screen shahidr100 Pro VB Databases 13 April 3rd, 2007 02:24 AM
Login Screen ashes0000 Word VBA 1 December 29th, 2006 03:00 AM
login trouble vijayaptetheone VB.NET 2002/2003 Basics 0 March 24th, 2006 03:30 PM
Trouble Opening Recordset NicholasM Classic ASP Databases 1 October 18th, 2003 04:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.