Re: DoCmd.TransferSpreadSheet query with paramaters
Originally posted by dav_evans
Hi I want to export some data from my access Db to excel using doCmd.TransferSpreadSheet. I'm able to export data using an access query but I want to be able to use a query that takes a parameter
Select * from table Where ID = [x]
if [x] comes from a listbox on a VBA form. Any ideas?
You can use something like that:
Dim SQL as string
For Each selectedItem In yourList.ItemsSelected
SQL = SQL & yourList.ItemData(selectedItem) & ","
SQL = Mid(SQL, 1, Len(SQL) - 1)
SQL = SQL & " INTO " & yourFileName
SQL = SQL & " FROM " & yourTableName
DoCmd.RunSQL (SQL) ' The table [yourTableName] will be created