Results 1 to 4 of 4
  1. #1
    graffiti is offline Newest Newbie ever
    Windows XP Access 2003
    Join Date
    Nov 2011
    Location
    Worthing, south coast of the UK
    Posts
    21

    Newbie Q. Comparing a variable with a record in a table.

    Hello one and all.



    I have a simple Q for you. Whats wrong with this please?

    Code:
     
        'Find the size of the Users table
        varRecordCount = DCount("UserName", "tblDBUsers")
        varLoop = 0
     
        'Compare the user name with record n of the users table.
        While varLoop <= varRecordCount
            If varUserName = tblDBUsers.UserName Then
                If varPassword = tblDBUsers.Password Then
                   varLoginDetailsOK = True
                End If
            End If
            varLoop = varLoop + 1
        Wend
     
        'ONLY if the password is OK do you do the following...
        If (varLoginDetailsOK = True) Then
    I see the error "object required" therefore I assume that I need to do something to prepare the way. I know the while loop isn't finished with the relevant exits, but the error starts before I get in to the loop itself. When stepping through it stops at the "While varLoop <= varRecordCount" expression.

    I guess it might be better done in SQL? I really am a newbie, picking up bits here and there. Thanks.

    Mike.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Not sure why it would stop there, but it will certainly have a problem here:

    If varUserName = tblDBUsers.UserName Then

    You can't refer to a table value that way. You'd need to open a recordset or use DLookup(). That said, looping the table is very inefficient. Use DLookup or DCount with a criteria to test the specific user:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    graffiti is offline Newest Newbie ever
    Windows XP Access 2003
    Join Date
    Nov 2011
    Location
    Worthing, south coast of the UK
    Posts
    21
    My apologies, I didn't post a thank you message. Here it is... Thanks for the help/ I said it would be simple.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, happy to have helped!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 04-20-2013, 10:12 AM
  2. Newbie needs help appending table
    By hara in forum Queries
    Replies: 6
    Last Post: 06-30-2010, 05:42 PM
  3. Replies: 11
    Last Post: 01-21-2010, 11:01 AM
  4. Newbie Table Setup
    By debl5 in forum Access
    Replies: 3
    Last Post: 05-15-2009, 07:46 AM
  5. Need help - Record set based on a program variable
    By ericargent in forum Programming
    Replies: 1
    Last Post: 09-19-2007, 08:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums