openrecordset--too few parameters

G

Guest

I'm getting a run-time error '3061' (too few parameters) and don't understand
why. Error occurs on the "Set R = D.OpenRecordSet(SQLText) line of the
function.

I'm opening a report from a form and trying to use code to replace tokens on
the report with field values from the form.

From the form "frmLetter" cmd button click event: DoCmd.OpenReport
"LtrRefund", acViewPreview

From the report "LtrRefund" OnOpen event: =filloutfrommap("ltrRefund")

Calls function on frmLetter class module:
Function FillOutFromMap(LetterName)

(in table "zLetterMap" the field "ltrName" contains the value "ltrRefund")

Dim F As Form, D As Database, R As Recordset, C As Control, SQLText As String
Set F = Forms![frmLetter]
Set C = Reports![ltrRefund]!lblAddr
Set D = DBEngine.Workspaces(0).Databases(0)
SQLText = "Select * from [zLetterMap] where [ltrname] = " & LetterName &
";"
Set R = D.OpenRecordset(SQLText)
Do Until R.EOF
C.Caption = Replace(C.Caption, R![Token], F(R![replacement]))
R.MoveNext
Loop
End Function

Seems to me I'm passing in the LetterName value of "ltrRefund", so why am I
"missing a parameter"?

Thanks!
 
G

Guest

Soon as I went to lunch I found the problem--forgot to include single quotes
so that my input table name would be read as a string. But once I make that
correction, I get new error:
If DoCmd.OpenReport "LtrRefund", acViewPreview, I get a flash of (my
report?) on the screen--then it disappears.

If acViewNormal, I get Run-time error 2501--the OpenReport action was
canceled. "You used a method of the DoCmd object to carry out an action in
VB, but then clicked Cancel in a dialog box." Well, no...and Debug just
brings me back to
DoCmd.OpenReport "LtrRefund", acViewNormal

If acViewDesign, the report opens in design mode, when I click on Preview, I
get "The Expression On Format you entered as the event property setting
produced the error: The expression you entered has a function containing the
wrong number of arguments."

So maybe adding single quotes didn't fix my problem? Do I need to use
chr(34)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top