running query export excel

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Access VBA Training and help » Running a Query to export to Excel with a parameter

Running a Query to export to Excel with a parameter

resolvedResolved · Medium Priority · Version 2016

Manny has attended:
Access Intermediate course
Access Advanced course

Running a Query to export to Excel with a parameter

Hi Guys,

i have a calender pop up that allows the user to enter a date that they wish to run a report for. the code is below. The issue is, when this runs it asks for another pop up box to enter the enter. It is a [xxx] parameter on an underlying query.

I wish it to pass the date into the RandBQ query. it looks to work fine but is asking for a second instance of a date despite this being passed through?

Thanks, Manny




Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Dim rs As DAO.Recordset

Set db = CurrentDb
Set qdf = db.QueryDefs("RandBQ")

For Each prm In qdf.Parameters
prm = Forms![CalenderSelectMaitlandF].Calendar0.Value
Next prm

Set rs = qdf.OpenRecordset

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, qdf.Name, "C:\Users\Manny.Chana\Documents\Macros\Pricing\Access\test.xls", True

RE: Running a Query to export to Excel with a parameter

Hi Manny,

Thank you for the forum question.

I cannot see anything that should display a second prompt (parameter query) in the code.

I am not sure why you are using a For Each Loop if you only want to transfer one date to the query.

Sorry based on the code I cannot help you.

Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Running a Query to export to Excel with a parameter

Hi Jens,

I went down multiple routes to try to resolve. In the end, I decided to do a make table query and kick that out to excel and then my other report is an auto generated pdf from the information.



Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter

Set db = CurrentDb
Set qdf = db.QueryDefs("myQ")

For Each prm In qdf.Parameters
prm = Forms![CalenderSelectF].Calendar0.Value
Next prm

On Error Resume Next
DoCmd.DeleteObject acTable, "RandBQT"
qdf.Execute
ddate = Format(Forms![CalenderSelectF].Calendar0.Value, "ddmmyyyy")
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "RandBQT", "myfilelocation " & ddate & ".xls", True
DoCmd.DeleteObject acTable, "RandBQT"

RE: Running a Query to export to Excel with a parameter

Hi Manny,

Did it resolve the problem?

Sometimes when Access return more parameter queries than expected it can be an expression issue. If a reference to field is misspelt Access see it as a parameter query.




Kind regards

Jens Bonde
Microsoft Office Specialist Trainer

Tel: 0207 987 3777
STL - https://www.stl-training.co.uk
98%+ recommend us

London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector

RE: Running a Query to export to Excel with a parameter

Hi Jens,

My solution did work. I seem to be having issues executing select queries in VBA. it is easier to make table via vba and then kick this out to either excel or pdf for reporting

Thanks again for your help.
Manny

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Access tip:

Changing MS Programs Text Size

A handy way to increase or decrease the size of text in Microsoft Word, Microsoft PowerPoint, Microsoft FrontPage, or Microsoft Publisher, first, select the text you want to resize.

Then, to increase the font size, press CTRL+SHIFT+>.

To decrease the font size, press CTRL+SHIFT+<.

View all Access hints and tips


Server loaded in 0.08 secs.