我有一个25000条记录的数据库,用DAO连接,在用like查询时,如果没有查到会出现错误7,我如果用where过滤掉前面的20000条,只剩下后面的5000条,则就是没查到不会出现错误,我如果从中间抽出1000条再用like查询时,如果没查到就会出现内存不足,即错误7,查到不会出现错误.下面是两种代码,欢迎指正:
出错代码:
Private Sub Command1_Click()
Dim ws As DAO.Workspace
Dim cn As DAO.Database
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim strxm As String
Dim STRxm2 As String
Set ws = Workspaces(0)
'On Error GoTo neicun:
Set cn = ws.OpenDatabase("G:\4.mdb")
'
Set rs = cn.OpenRecordset("select * from chen where id>15000 and id<16000")
rs.MoveLast
Text1.Text = rs.RecordCount
rs.FindFirst "name like '刘*三'"
Text2.Text = rs.Fields("id")
Text3.Text = rs.Fields("name")
rs.Close
cn.Close
ws.Close
End Sub
不出错代码:
Private Sub Command1_Click()
Dim ws As DAO.Workspace
Dim cn As DAO.Database
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim strxm As String
Dim STRxm2 As String
Set ws = Workspaces(0)
'On Error GoTo neicun:
Set cn = ws.OpenDatabase("G:\4.mdb")
'
Set rs = cn.OpenRecordset("select * from chen where id>20000")
rs.MoveLast
Text1.Text = rs.RecordCount
rs.FindFirst "name like '刘*三'"
Text2.Text = rs.Fields("id")
Text3.Text = rs.Fields("name")
rs.Close
cn.Close
ws.Close
End Sub