+ Reply to Thread
Results 1 to 6 of 6

Access VBA - copy the Crosstab Querry data into the selected Excel file

  1. #1
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Access VBA - copy the Crosstab Querry data into the selected Excel file

    Hi all,

    I'm currently trying to put together (supposedly) simple code, that would copy over the data from my Access Database (Crosstab Querry) into the Excel, that the user can select himself.

    I've already written some piece of code, which is however breaking in the line, that should select relevant data, ending with the error message:


    PHP Code: 
    "Run-time error '-2147217900 (80040e14)':

    Syntax error in FROM clause" 

    Could anyone please help me to adjust the code to be able to select relevant data, that I could later transfer into the Excel?

    HTML Code: 
    'THIS IS THE LINE WHERE THE CODE BREAKS:



    HTML Code: 


    'Could anyone please suggest, how to form the line of code so that I could select the data from all four columns from Crosstab Querry. The data, that would be later copied over into the Excel file?


    HTML Code: 

    Thank you very much for any help!
    Last edited by lukelucky; 09-29-2017 at 03:54 AM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,859

    Re: Access VBA - copy the Crosstab Querry data into the selected Excel file

    If you created the crosstab query in the QBE and then looked at the SQL statement for the query. What is the SQL statement if you do it that way. You can then change it as needed for VBA.

    For simplicity sake, I usually create all my queries in the QBE and then write code to export the named query. Code then would look like this:

    Please Login or Register  to view this content.
    I create a form that has a drop down with a list of all queries. I add a command button that runs the above code. It puts the query into excel on the desktop of the user. If you want to not use the QBE and have the SQL statement in VBA, then look at this link as to how to do that.

    http://allenbrowne.com/ser-71.html
    Last edited by alansidman; 09-29-2017 at 04:21 AM.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Re: Access VBA - copy the Crosstab Querry data into the selected Excel file

    Thank you for your reply. I haven't written the query as I created it in design view. However, the resulting query looks like this:

    HTML Code: 
    I've joined here the results of two other queries.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,859

    Re: Access VBA - copy the Crosstab Querry data into the selected Excel file

    Here is your SQL statement converted to VBA

    Please Login or Register  to view this content.
    Is this what you were looking for?

  5. #5
    Registered User
    Join Date
    02-05-2014
    Location
    Prague, Czech Republic
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    72

    Re: Access VBA - copy the Crosstab Querry data into the selected Excel file

    Excellent, thank you for your help!

    Could I have one additional question? Would it be possible by chance to copy only the data without row headings?

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,859

    Re: Access VBA - copy the Crosstab Querry data into the selected Excel file

    I am not aware of a way to do this in Access. You could write additional code to format your excel spreadsheet to remove the headers.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to AutoFilter create PDF/Mail and copy selected data to Template Excel file
    By iancoupal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2014, 05:47 PM
  2. External Data - Crosstab Query Access
    By RobLmrcpvf in forum Excel General
    Replies: 2
    Last Post: 06-28-2011, 12:44 PM
  3. Split access table or querry in several excell sheet
    By wcedeno in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-25-2011, 04:49 PM
  4. Replies: 1
    Last Post: 03-08-2011, 12:31 PM
  5. Linking Access Crosstab problem
    By tjm2009 in forum Excel General
    Replies: 0
    Last Post: 10-01-2009, 08:20 AM
  6. Copy Data from Excel Files (from a Sharepoint) to Access MDB File
    By LordMarcus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-06-2009, 05:59 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1