Solved Error 3061 - Too few parameters. Expected1? (1 Viewer)

Number11

Member
Local time
Today, 12:59
Joined
Jan 29, 2020
Messages
208
So i have this criterial set in a query that I am looking for export using the

Dim rst
Dim XL As Excel.Application
Set XL = CreateObject("excel.application")
Dim vFile

vFile = "template location"
Set rst = CurrentDb.OpenRecordset("BRequest")
With XL
.Visible = False
.Workbooks.Open vFile
.Sheets("BC").Select
.Range("A4").Select
.ActiveCell.CopyFromRecordset rst
.ActiveWorkbook.SaveAs filename:=("Save file name and location"
.ActiveWorkbook.Close
.Application.Quit


The query runs fine if i run this manually but not from the above i get the runtime error

criteria in query is set as

[Forms]![BRequest]![Account-No]
 

arnelgp

error reading drive A:
Local time
Today, 20:59
Joined
May 7, 2009
Messages
10,858
use QueryDefs:
Code:
    Dim rst As DAO.Recordset
    With CurrentDb.QueryDefs("BRequest")
        .Parameters(0) = [Forms]![BRequest]![Account-No]
        Set rst = .OpenRecordset
    End With
 

Number11

Member
Local time
Today, 12:59
Joined
Jan 29, 2020
Messages
208
use QueryDefs:
Code:
    Dim rst As DAO.Recordset
    With CurrentDb.QueryDefs("BRequest")
        .Parameters(0) = [Forms]![BRequest]![Account-No]
        Set rst = .OpenRecordset
    End With
Thanks i tried that and now getting error 3265 - Item not found in this collection?
 

arnelgp

error reading drive A:
Local time
Today, 20:59
Joined
May 7, 2009
Messages
10,858
check the Form BRequest if it is Open?
if open check if there is a Textbox, named [Account-No].
 

Number11

Member
Local time
Today, 12:59
Joined
Jan 29, 2020
Messages
208
check the Form BRequest if it is Open?
if open check if there is a Textbox, named [Account-No].
Yeah form is open and has text box called Account-No, i did also remove the criteria from the query is that correct?
 

namliam

The Mailman - AWF VIP
Local time
Today, 13:59
Joined
Aug 11, 2003
Messages
11,680
word to the wize, use a naming convention and avoid using special characters like spaces, -@#!#%^*&( and alike.

Your Account-No would be txtAccountNumber
Your form BRequest would be frmBrequest
Your query for that form would be qryBrequest
Your table for that form would be tblBrequest
Etc etc..

This will help you identify and find objects much easier and make spotting typo's easier a well.
 

Users who are viewing this thread

Top Bottom