现有一张access数据表,名称为1,其中有个字段为mudi,Mudi中有三个值:1,6,13。我现在想编程解决如下问题:当mudi值为6时,指针移到前一条记录,如果前一条记录值为13,则将这个mudi值为6的记录的所有字段放到查询表2中,如果mudi值为1则将这个mudi值为6的记录的所有字段放到查询表3中,我编了个小程序,但运行时总是说Set qdf = dbs.CreateQueryDef(queryName, strSQL)有错,请高手帮忙看看是怎么错了(不只是这句,可能还会有其它语句有问题,请指正),谢谢! 程序如下: Option Compare Database Private strSQL As String Private queryName As String Private dbs As Database Private qdf As QueryDef
Private Sub Command0_Click()
Dim cn As New ADODB.Connection Dim rshc As New ADODB.Recordset Set cn = CurrentProject.Connection rshc.Open "select * from 1", cn, 1, 3, 1 rshc.MoveFirst
With rshc If Not .EOF Then .Find "mudi=6" .MovePrevious If rshc.Fields("mudi") = 13 Then .MoveNext strSQL = " SELECT * FROM 1" queryName = "2" Set dbs = CurrentDb Set qdf = dbs.CreateQueryDef(queryName, strSQL) Else .MoveNext strSQL = " SELECT * FROM 1" queryName = "3" Set dbs = CurrentDb Set qdf = dbs.CreateQueryDef(queryName, strSQL) End If Else .MoveNext End If End With
rshc.Close cn.Close MsgBox "处理完毕" End Sub |