Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error With SQL in VBA

Status
Not open for further replies.

jdgreen

Technical User
Mar 21, 2001
144
US
I am continually getting an error with some pretty basic code. The error is "error 3061 too few parameters expected 1" which normally means there's a problem with the SQL. The code is below:

Private Sub Command11_Click()
On Error GoTo Err_Handler

Dim strReport As String
Dim strMailTo As String
Dim strFileName As String
Dim strBrand As String
Dim strSQL As String
Dim rs As DAO.Recordset
Dim db As DAO.Database

strBrand = Me.Combo2

strReport = "rptEMailCatalog"
strFileName = "U:\" & strBrand & " New Releases.pdf"

''DoCmd.OutputTo acOutputReport, strReport, acFormatPDF, strFileName

strSQL = "SELECT qryEMailTo.Email FROM qryEMailTo;"

Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)




Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & " - " & Err.Description, , "cmdPreview_Click"
End If
Resume Exit_Handler
End Sub

Any help would be greatly appreciated.


John Green
 
What is the SQL code of qryEMailTo ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It runs fine

SELECT CustData.Email
FROM CustBrandsFlat INNER JOIN CustData ON CustBrandsFlat.CustID = CustData.[customercode]
WHERE (((CustBrandsFlat.Brand)=[Forms]![frmEmailing]![Combo2]))
GROUP BY CustData.Email
HAVING (((CustData.Email)<>IsNull()));


John Green
 
Here is the expected parameter:
[Forms]![frmEmailing]![Combo2]

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Replace this:
strSQL = "SELECT qryEMailTo.Email FROM qryEMailTo;"
Set db = CurrentDb
With this:
Code:
Dim qdf As QueryDef, prm As DAO.Parameter
strSQL = "qryEMailTo"
Set db = CurrentDb
Set qdf = db.QueryDefs(strSQL)
For Each prm In qdf.Parameters
    prm.Value = Eval(prm.Name)
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top