本文介绍了FindFirst在索引字段上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Access 2002数据库上使用DAO 3.6,我得到了意想不到的

结果使用FindFirst方法。这是要测试的简单代码:


Public Sub FindIt()

Dim db作为数据库,rs作为记录集

Dim sCriteria As String


设置db = DBEngine.Workspaces(0).Databases(0)

设置rs = db.OpenRecordset( tblTest,dbOpenDynaset


''sCriteria =" MyField =''24""直径" ''< - Works

sCriteria =" MyField ="" 24""""直径QUOT;"" ''< - 失败

rs.FindFirst sCriteria


Debug.Print sCriteria

Debug.Print" rs。 NoMatch =" &安培; rs.NoMatch


结束子


和即时窗口输出:


MyField =' '24"直径''

rs.NoMatch = False


MyField =" 24""直径

rs.NoMatch = True


tblTest有字段ID(自动编号)和MyField(文本50):

1 12英寸直径

2 24"直径

3 36"直径


第二个标准,使用双引号作为分隔符失败

如果tblTest.MyField被索引。但如果删除索引

,它会成功运行。任何人都可以复制或解释这种意外行为
来自FindFirst的
吗?


Rick Collard

Using DAO 3.6 on an Access 2002 database, I''m getting unexpected
results with the FindFirst method. Here''s the simple code to test:

Public Sub FindIt()

Dim db As Database, rs As Recordset
Dim sCriteria As String

Set db = DBEngine.Workspaces(0).Databases(0)
Set rs = db.OpenRecordset("tblTest", dbOpenDynaset)

''sCriteria = "MyField = ''24"" Diameter''" ''<-- Works
sCriteria = "MyField = ""24"""" Diameter""" ''<-- Fails
rs.FindFirst sCriteria

Debug.Print sCriteria
Debug.Print "rs.NoMatch = " & rs.NoMatch

End Sub

And the immediate window output:

MyField = ''24" Diameter''
rs.NoMatch = False

MyField = "24"" Diameter"
rs.NoMatch = True

tblTest has fields ID (autonumber) and MyField (text 50):
112" Diameter
224" Diameter
336" Diameter

The second criteria, which uses double-quotes as the delimiter fails
if tblTest.MyField is indexed. But it works successfully if the index
is removed. Can anyone duplicate or explain this unexpected behavior
from FindFirst?

Rick Collard
www.msc-lims.com

推荐答案



任何人都可以花几分钟时间复制问题吗? TIA


Rick Collard





任何人都可以花几分钟时间来复制问题? TIA


Can anyone spare a few minutes to duplicate the problem? TIA



我试过

sCriteria =" TestFld =''" &安培; " 24英寸;"直径QUOT; &安培; "''"

在NoMatch上出现错误


起床和去




沙拉,

感谢您的测试。是的,该语法正常工作,因为

单引号分隔符不在搜索字符串中。你可以尝试

问题语法:


sCriteria =" TestFld ="" 24""""直径"


以上是有效的语法,但是如果

TestFld被编入索引,则无法找到匹配项。如果NoMatch为True则移除索引并查看是否

NoMatch现在为假。

Rick Collard


这篇关于FindFirst在索引字段上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 12:30
查看更多