Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    cbrsix is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    214
    @John_G - I know..I had to remove the [tblUsers.Password] because when that was in, it came back with a runtime error (see attachment Capture)Click image for larger version. 

Name:	Capture.JPG 
Views:	7 
Size:	19.5 KB 
ID:	8235 then when I went to view the code it highlighted the strcomp() line. When I remove [tblUsers.Password] it comes back always wrong.

  2. #17
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    lol yeah, I caught that right after I posted. That's why I changed my post to mention "Password" :P

  3. #18
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    When you're referencing a Recordset field, you need to use a different format than you do in a straight SQL Query.

    Code:
    Dim rst as DAO.Recordset ' Created a VBA Object to hold your Query Results
    Set rst = CurrentDb().OpenRecordset("<Include SQL Query Here>", dbOpenSnapshot) ' Runs your SQL Query and loads the results in to your VBA Object
    At this point, things differ depending on how many Records your Query can return. . .

    If you're sure the Query will only return a single Record, then you can use the following code to check against it:
    Code:
    If StrComp(rst("<Insert Field Name Here>"), Me!txtPassword, 0) = 0 Then
      ' Do your stuff
    Else
      ' Do your stuff
    End If
    If there could be multiple Records in the Query results, then you'll need to search for the one you want first
    Code:
    Dim strCriteria as String ' the String that'll hold our search criteria
    
    strCriteria = "[<Insert Field Name Here>]='" & <WhatYou'reLookingFor> & "'"
    rst.FindFirst strCriteria ' Find the first Record that matches your search. If the search doesn't find anything, then rst.NoMatch will equal True
    
    'Always check for rst.NoMatch!
    If rst.NoMatch = True Then
      ' No matching Record was found!
    Else
      ' We found a matching Record, do your StrComp() check!
      If StrComp(rst("<Insert Field Name Here>"), Me!txtPassword, 0) = 0 Then
        ' Do your stuff
      Else
        ' Do your stuff
      End If
    End If

  4. #19
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The syntax of [tblUsers.Password] isn't right - it should be [tblUsers].[Password]

    Easier, though, is to use DLookup:

    Password = DLookup("Password","tblUsers","Username = '" & txtusername & "'")

    Change Username to the correct field name in tblUsers if necessary.

    John

  5. #20
    cbrsix is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    214
    Thanks for both of your guys' help. The dlookup() seems to be working exactly how I want it to so far. I am still curious as to why the original code in my sample db would work fine but when I put it in my other db, it gave me all these problems. Any ideas as to why this would be, for my future reference..?

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. make textbox lookup values case insensitive
    By sephiroth2906 in forum Forms
    Replies: 2
    Last Post: 04-22-2011, 10:36 AM
  2. Replies: 1
    Last Post: 03-30-2011, 02:29 PM
  3. F1 Context sensitive help in Access 2002
    By NOTLguy in forum Programming
    Replies: 6
    Last Post: 10-25-2010, 02:50 PM
  4. Time sensitive data
    By ViRi in forum Forms
    Replies: 3
    Last Post: 02-27-2010, 01:04 AM
  5. is access case-sensitive?
    By pen in forum Programming
    Replies: 1
    Last Post: 04-07-2009, 05:13 AM

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