lookingforK
Registered User.
- Local time
- Today, 11:03
- Joined
- Aug 29, 2012
- Messages
- 48
Hi,
I am using MS Access 2010 to export data into MS Excel 2010 spreadsheets.
I am just wondering:
Is there a way to set the Parameter value for the query via VBA?
For example:
There are 10 regional managers. When I click a button on a form, 10 sets of data per manager are going to be exported into Excel spreadsheets.
I have created a saved query named [For exporting] with a parameter [Manager Name] for the field [Master Table].[Manager].
The VBA for the button has 2 subs:
1) Sub 1 for the loop for 10 managers
2) Sub 2 (i.e. GenerateReport) for exporting dataset into Excel spreadsheet one by one for each manager.
Here, I use the command 'TransferSpreadsheet'
How to write the code in the red part?:banghead:
Thank you in advance.
I am using MS Access 2010 to export data into MS Excel 2010 spreadsheets.
I am just wondering:
Is there a way to set the Parameter value for the query via VBA?
For example:
There are 10 regional managers. When I click a button on a form, 10 sets of data per manager are going to be exported into Excel spreadsheets.
I have created a saved query named [For exporting] with a parameter [Manager Name] for the field [Master Table].[Manager].
The VBA for the button has 2 subs:
1) Sub 1 for the loop for 10 managers
Code:
[FONT=Times New Roman][COLOR=black][COLOR=black][FONT=Times New Roman]...[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]strQuery = "SELECT DISTINCT [Master Table].[Manager] FROM [Master Table] WHERE ((([Master Table].[Manager]) Is Not Null));"[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Set rstStores = CurrentDb.OpenRecordset(strQuery)[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]rstStores.MoveFirst[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Do Until rstStores.EOF[/FONT][/COLOR]
[COLOR=red][FONT=Times New Roman]{assign the value [/FONT][FONT=Calibri][U][I]rstStores![Manager][/I][/U][/FONT][FONT=Times New Roman] to the Parameter of the saved query}[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman][B][COLOR=blue]GenerateReport[/COLOR][/B] strReportPath, Trim(rstStores![Manager])[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]rstStores.MoveNext[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]Loop[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]End If[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]...[/FONT][/COLOR]
[/COLOR][/FONT]
2) Sub 2 (i.e. GenerateReport) for exporting dataset into Excel spreadsheet one by one for each manager.
Here, I use the command 'TransferSpreadsheet'
Code:
[FONT=Times New Roman][COLOR=black][COLOR=black][FONT=Times New Roman]...[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]DoCmd.TransferSpreadsheet acExport, , "For exporting", ReportPath & "\Temp1.xlsx"[/FONT][/COLOR]
[COLOR=black][FONT=Times New Roman]...[/FONT][/COLOR]
[/COLOR][/FONT]
How to write the code in the red part?:banghead:
Thank you in advance.
Last edited: