我在MS ACCESS 2007中设置了一个查询(Qoff2),如下所示:
SELECT off.FNAM, inc.RECEIVED_DT,
inc.FILENUM
FROM (INC LEFT JOIN AIO ON INC.INCNUM = AIO.INCNUM) LEFT JOIN OFF ON AIO.OFFNUM = off.OFFNUM
WHERE ((inc.ID)=[forms]![form].[text10]));
我有一个模块,有这个代码从MS Access获取查询。
Public Sub OpenRecordset()
Dim qdf As QueryDef
Set qdf = CurrentDb.QueryDefs("QOff2")
Dim db As Database
Dim rs As Recordset
Dim StrBusinesses As String
Set rs = qdf.OpenRecordset
If rs.EOF And rs.BOF Then
MsgBox ("No businesses exist for this Customer")
Exit Sub
Else
rs.MoveFirst
End If
StrBusinesses = ""
Do While Not rs.EOF
StrBusinesses = StrBusinesses & rs!Fnam & ", "
rs.MoveNext
Loop
rs.Close
StrBusinesses = Left(StrBusinesses, Len(StrBusinesses) - 2)
Forms!Form.Test = StrBusinesses
Set rs = Nothing
End Sub
我想要的是记录集进行查找,并将[forms]![form]。[text10]与Qoff2.filenum进行比较,然后将所有相关的fnam列入[forms]![form] .test,但由于某种原因,我无法让它发挥作用。我得到一个太少的参数错误预期1错误。当我在访问中运行查询并打开表单时,它工作得很好。我在vba中运行模块时出现参数太少的错误,并突出显示Set rs = qdf.OpenRecordset。
答案 0 :(得分:0)
您需要指定参数:
Set qdf = CurrentDb.QueryDefs("QOff2")
qdf.Parameters(0).Value = [forms]![form]![text10]