Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Posts
    10

    Unanswered: DoCmd.TransferSpreadSheet query with paramaters

    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

    eg:
    Select * from table Where ID = [x]

    if [x] comes from a listbox on a VBA form. Any ideas?

    thanks,
    Dav

  2. #2
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb 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

    eg:
    Select * from table Where ID = [x]

    if [x] comes from a listbox on a VBA form. Any ideas?

    thanks,
    Dav
    You can use something like that:

    Dim SQL as string

    For Each selectedItem In yourList.ItemsSelected
      SQL = SQL & yourList.ItemData(selectedItem) & ","
    Next
    SQL = Mid(SQL, 1, Len(SQL) - 1)
    SQL = SQL & " INTO " & yourFileName
    SQL = SQL & " FROM " & yourTableName

    DoCmd.RunSQL (SQL) ' The table [yourTableName] will be created

    Now you can export the created table to Excel



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •