0

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.

1 Answer 1

0

You need to specify the parameter:

Set qdf = CurrentDb.QueryDefs("QOff2")
qdf.Parameters(0).Value = [forms]![form]![text10]
Sign up to request clarification or add additional context in comments.

1 Comment

that works great, except I have another issue that I will have to post now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.