简体   繁体   中英

Too Few Parameters with Recordset pulling query from MS Access 2007

I have a query (Qoff2) set up in MS ACCESS 2007 that looks like this:

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]));

And I have a module that has this code to grab the query from 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

What I want is for the recordset to do a lookup, and compare [forms]![form].[text10] to Qoff2.filenum, then list all the related fnam's into [forms]![form].test, but for some reason I can't get it to work. I get a too few paramaters error expected 1 error. It works just fine when I run the query inside access and have the form open. I get an error of too few parameters when I run the module in vba and it highlights Set rs = qdf.OpenRecordset.

You need to specify the parameter:

Set qdf = CurrentDb.QueryDefs("QOff2")
qdf.Parameters(0).Value = [forms]![form]![text10]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM