本文介绍了ADO .Find总会得到EOF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我为测试ADO Find而开发的一些代码,该代码不起作用.
无论尝试什么,我都会得到EOF.
谁能帮忙吗?我做错了什么?
我正在搜索的表具有:
Below is some code I developed to test the ADO Find which is not working.
I always get EOF no matter what I Try.
Can anyone please help? What am I doing wrong?
The table I am searching has:
Tic-Exchange - string
Tic-Ticker - string
作为主键.还有很多其他领域.
我知道表格中已经插入了Exchange和Ticker的值.
as the primary key. It many other fields.
I know that the values I have plugged into both Exchange and Ticker are in the table.
Sub FindTest()
Dim rst As ADODB.Recordset
Dim booEmpty As Boolean
Dim booNotFound As Boolean
Dim strTicker As String
Dim strSQL As String
Dim strExchange As String
strExchange = "ASX"
'Open Files
Set rst = New ADODB.Recordset
With rst
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.CursorLocation = adUseServer
strSQL = "Select * FROM tblTicker" & _
" WHERE tblTicker![Tic-Exchange] = """ & strExchange & """" & _
" ORDER BY tblTicker![Tic-Ticker]"
Debug.Print "SQL1: " & strSQL
.Open strSQL, options:=adCmdText
End With
If rst.EOF Then
'Do Stuff
booEmpty = True
End If
Debug.Print "Exch: " & rst![Tic-Exchange] & " Tick: " & rst![Tic-Ticker] & " ISIN: " & rst![Tic-ISIN]
'Find Ticker Record
strTicker = "BHP"
strSQL = "[Tic-Ticker] = """ & strTicker & """"
Debug.Print "SQL2: " & strSQL
booNotFound = False
If Not booEmpty Then
rst.MoveFirst
rst.Find strSQL, adSearchForward
If rst.EOF Then
Debug.Print "Not Found"
booNotFound = True
End If
End If
If booEmpty Or booNotFound Then
'Create NEW record Here
booEmpty = False
Else
'Update EXISTING record Here
End If
rst.Close
Set rst = Nothing
End Sub
推荐答案
bFind = False
With rst
.MoveFirst 'mark this line if error
Do While NOT .EOF
bFind = True
'do what you want to do
.MoveNext
Loop
End With
这篇关于ADO .Find总会得到EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!