FindFirst and double quotes (1 Viewer)

jdraw

Super Moderator
Staff member
Local time
Yesterday, 19:18
Joined
Jan 23, 2006
Messages
15,379
You should always include
Option Explicit as second line in each module
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 19:18
Joined
Jan 23, 2006
Messages
15,379
For what it's worth:

Using the same table and records as posted in #12, this works when

1. Set rs = db.OpenRecordset("select * from acanvend", dbReadOnly) or
2. Set rs = db.OpenRecordset("select * from acanvend", dbOpenSnapshot, dbReadOnly)
3. Set rs = db.OpenRecordset("select * from acanvend", dbOpenSnapshot)

It results in NoMatch (doesn't work) when using dbOpenDynaset
Set rs = db.OpenRecordset("select * from acanvend", dbOpenDynaset) OR
Set rs = db.OpenRecordset("select * from acanvend", dbOpenDynaset, dbReadOnly)

Code:
Sub DoubleQuoteAgain()
    Dim rs As DAO.Recordset
    Dim findcriteria As String
    Dim db As DAO.Database
    Set db = CurrentDb
    'Set rs = db.OpenRecordset("select * from acanvend", dbReadOnly)                             'works
    'Set rs = db.OpenRecordset("select * from acanvend", dbOpenSnapshot)                     'works
    'Set rs = db.OpenRecordset("select * from acanvend", dbOpenSnapshot, dbReadOnly)'works
    'Set rs = db.OpenRecordset("select * from acanvend", dbOpenDynaset)                        'does not work
    Set rs = db.OpenRecordset("select * from acanvend", dbOpenDynaset, dbReadOnly)    'does not work
    findcriteria = "acanvend.terr_cd = '""D''Loro""'"  ': from Cheekybuddha
    Debug.Print findcriteria
    rs.FindFirst findcriteria
    If rs.NoMatch Then
        Debug.Print "No matching record was found"
    End If
    Debug.Print rs!vend_num; rs!TERR_CD
    rs.Close
    If Not rs Is Nothing Then Set rs = Nothing
End Sub
 

cheekybuddha

AWF VIP
Local time
Today, 00:18
Joined
Jul 21, 2014
Messages
2,280
@jdraw,

Since you're testing, what happens if you try:
Code:
Sub DoubleQuoteOnceMore()
    Dim rs As DAO.Recordset
    Dim sql As String
    Dim db As DAO.Database
    Set db = CurrentDb
    sql = "SELECT * FROM acanvend WHERE acanvend.terr_cd = '""D''Loro""'"
    Debug.Print sql
    'Set rs = db.OpenRecordset(sql , dbReadOnly)
    'Set rs = db.OpenRecordset(sql, dbOpenSnapshot) ' identical to above
    'Set rs = db.OpenRecordset(sql, dbOpenSnapshot, dbReadOnly)
    'Set rs = db.OpenRecordset(sql, dbOpenDynaset)
    Set rs = db.OpenRecordset(sql, dbOpenDynaset, dbReadOnly)
    If Not rs.EOF Then Debug.Print rs!vend_num; rs!TERR_CD
    rs.Close
    If Not rs Is Nothing Then Set rs = Nothing
End Sub
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 19:18
Joined
Jan 23, 2006
Messages
15,379
Hi David,

This resulted in
SELECT * FROM acanvend WHERE acanvend.terr_cd = '"D''Loro"'
4 "D'Loro"

with all 5 versions of the Set rs....

?? Is it possible that FindFirst is not compatible with dbOpenDynaSet??

According to M$oft documentation
FindFirst
Locates the first record in a dynaset- or snapshot-type Recordset object that satisfies the specified criteria and makes that record the current record (Microsoft Access workspaces only).
 

cheekybuddha

AWF VIP
Local time
Today, 00:18
Joined
Jul 21, 2014
Messages
2,280
So each variation produced the desired result with:
Code:
Debug.Print rs!vend_num; rs!TERR_CD
?
 

Josef P.

Well-known member
Local time
Today, 01:18
Joined
Feb 2, 2023
Messages
827
Could reproduce it now: It must be an indexed data field, so that it is not found when comparing with =.
With like without * it works.

And it gets even better:
fldSAdderess1 = ''+'"Rye Roxley''s"' => Match found
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 19:18
Joined
Jan 23, 2006
Messages
15,379
So each variation produced the desired result with:
Code:
Debug.Print rs!vend_num; rs!TERR_CD
?
Yes. I was editing my response to add that info.

As you can see in the graphic below, field Terr_Cd is indexed (duplicates OK)

2023-08-28 17_16_04-Access -acanvend table design has index.png
 
Last edited:

Josef P.

Well-known member
Local time
Today, 01:18
Joined
Feb 2, 2023
Messages
827
For me, this is a bug.

Results with indexed field:
T1 = 'ab''c' => no match
T1 = "ab'c" => match found
T1 = 'ab"c' => match found
T1 = "ab""c" => no match

T1 = '' + 'ab''c' => match found
T1 like 'ab''c' => match found
T1 like 'ab''c*' => no match

Note: records with ab'c and ab"c exists in table.
 

Attachments

  • FindFirstBug.zip
    51.2 KB · Views: 50
Last edited:

Users who are viewing this thread

Top Bottom