以下是我的代码。一个简单的循环,遍历查询中的记录(qryMasterImageFolders),然后调用子fs.listImages ...
但是,我仍然收到3061错误,并且以下行突出显示:
Set rst = qdf.OpenRecordset()
查询中确实包含记录,我已经检查了拼写-我缺少什么?
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim qdf As DAO.QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("qryMasterImageFolders")
Set rst = qdf.OpenRecordset()
With rst
Do Until .EOF
fs.listImages DLookup("ImageFolder", "qryMasterImageFolders")
.MoveNext
Loop
End With
rst.Close
Set rst = Nothing
Set qdf = Nothing
Set db = Nothing
答案 0 :(得分:1)
我更改了代码,现在可以正常工作了:
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT ImageFolder FROM tmpImagePaths")
'Check to see if the recordset actually contains rows
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst 'Unnecessary in this case, but still a good habit
Do Until rs.EOF = True
fs.listImages DLookup("ImageFolder", "qryMasterImageFolders")
'Move to the next record. Don't ever forget to do this.
rs.MoveNext
Loop
Else
MsgBox "There are no records in the recordset."
End If
MsgBox "Finished looping through records."
rs.Close 'Close the recordset
Set rs = Nothing 'Clean up
答案 1 :(得分:0)
您应该做的事情:
Set rs = db.OpenRecordset("qryMasterImageFolders")