Results 1 to 11 of 11
  1. #1
    robjones01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    8

    FindFirst with AND statement

    I'm having a real issue with the below code


    strDate = Format(Now, "Short Date")
    stLinkCriteria = "[CardID]='" & Me![tCard_ID] & "'"
    stSearchDupeCheckIn = "(([DateVisited]=#" & strDate & "#) And ([CardID]='" & Me.tCard_ID.Value & "'))"
    Set rsMembers = CurrentDb.OpenRecordset("tblMembers")
    Set rsAudit_Log = CurrentDb.OpenRecordset("tblAudit_Log")
    strMemberNumber = Null
    strFullMember_Number = Null
    strTitle = Null
    strFirstName = Null
    strSurname = Null
    strCardID = 0


    rsAudit_Log.FindFirst stSearchDupeCheckIn
    If rsAudit_Log.NoMatch Then
    GoTo ContinueSearch
    Else
    GoTo EndScript
    End If


    It errors at the FindFirst with the following message:

    "Operation is not supported for this type of object"

    I've tried everything to no avail...any help is much appreciated

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    how do you declare the rsAudit_log variable? Have you tried Dim rsAudit_log as Dao.recordset?

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    Try this:
    Code:
    stSearchDupeCheckIn = "[DateVisited]=#" & strDate & "# And [CardID]=" & tCard_ID

  4. #4
    robjones01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    8
    Unfortunately it's still not working, here's the full code;

    Code:
    Dim stDocName, stLinkCriteria, stSearchDupeCheckIn, strMemberNumber, strFullMember_Number, strTitle, strFirstName, strSurname, strCardID As String
    Dim rsMembers, rsAudit_Log, rsVisitors As Recordset
    Dim strAuditNum As Long
    Dim strDate As Date
    
    strDate = Format(Now, "Short Date")
    stLinkCriteria = "[CardID]='" & Me![tCard_ID] & "'"
    stSearchDupeCheckIn = "[DateVisited]=#" & strDate & "# And [CardID]=" & tCard_ID
    
    Set rsMembers = CurrentDb.OpenRecordset("tblMembers")
    Set rsAudit_Log = CurrentDb.OpenRecordset("tblAudit_Log")
    
    strMemberNumber = Null
    strFullMember_Number = Null
    strTitle = Null
    strFirstName = Null
    strSurname = Null
    strCardID = 0
    
    
    rsAudit_Log.FindFirst stSearchDupeCheckIn
    If rsAudit_Log.NoMatch Then
        GoTo ContinueSearch
    Else
        GoTo EndScript
    End If
    
    ContinueSearch:
    I'm at a loss as I've done this many times and its not working suddenly.

    It's errors at this code
    Code:
    rsAudit_Log.FindFirst stSearchDupeCheckIn
    I've tried moving to the last and first record prior to running the search but it still doesn't work.

    The DateVisited field is set as a date, and the CardID is a Short Text field.

  5. #5
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    CardID requires quotes around it if it is a text field.

    stSearchDupeCheckIn = "[DateVisited]=#" & strDate & "# And [CardID]='" & tCard_ID & "'"

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    This may not be a direct cause, but with Access, if you do not explicitly DIM your variables/objects they will default to Variant.
    So you would use this general approach:

    Dim strDocName as String
    Dim strTitle as String

    or

    Dim strDocName as String, strTitle as String, rsAudit_Log as DAO.Recordset

    everything is explicitly Dimmed.

    ??What exactly is the purpose of the Audit log in your set up??

  7. #7
    robjones01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    8
    Quote Originally Posted by aytee111 View Post
    CardID requires quotes around it if it is a text field.

    stSearchDupeCheckIn = "[DateVisited]=#" & strDate & "# And [CardID]='" & tCard_ID & "'"
    I’ve tried this and it still produces the same error.

  8. #8
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I'm not sure what is in strDate. "Format" produces a text field altho you have defined it as a date, so I don't know what will be produced. A far safer way would be
    "DateVisited=Date()"

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,114
    As Orange pointed out I believe it is the way you declare your variables. The way you have it now rsAudit_Log is a variant, not a DAO.recordset.

    Cheers,
    Vlad

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  11. #11
    robjones01 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    8
    Guys, I solved this by adding 'dbopendynaset' to the open recordset statement...working fine now.

    Thanks for your help

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

Similar Threads

  1. FindFirst error
    By Bazsl in forum Programming
    Replies: 6
    Last Post: 03-01-2017, 09:21 AM
  2. Replies: 3
    Last Post: 11-22-2014, 01:20 PM
  3. Recordset FindFirst
    By Praveenevg in forum Access
    Replies: 1
    Last Post: 08-18-2014, 12:55 PM
  4. .FindFirst problem
    By akhmadahdiyat in forum Programming
    Replies: 2
    Last Post: 11-29-2013, 12:27 AM
  5. Using FindFirst code
    By saltydawg617 in forum Access
    Replies: 2
    Last Post: 07-29-2011, 05:21 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