Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Collins is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    107


    Quote Originally Posted by pbaldy View Post
    To address this:



    The part that gets data is:

    'SQL statement to retrieve data from database
    SQL = "SELECT PartNo, PartName, Price, SalePrice, " & _
    "(Price - SalePrice) / Price AS Discount " & _
    "FROM Parts " & _
    "ORDER BY PartNo "

    So you can replace that SQL with your own. In other words, your fields in the SELECT clause and your table or query instead of Parts. At the very simplest:

    SQL = "SELECT * FROM YourTableOrQuery"

    which would return all fields and all records.
    I replaced all the SQL from the source code and replaced it with SQL = "SELECT * QueryExportData"
    When I ran it I received an error " Error Number: 3075=Syntax error (missing operator) in query expression '* QueryExportData'. "

    Thoughts??? I'm sure it's me...

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Need FROM keyword.

    SELECT * FROM QueryExportData
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    Collins is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    107
    Quote Originally Posted by June7 View Post
    Need FROM keyword.

    SELECT * FROM QueryExportData
    That got it. It just exported to a spreadsheet.

    Let me tinker with the formatting part of the code and make sure I don't have any other questions.

    Thanks a ton guys!!!

  4. #19
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    A trick I've often used is to record a macro in Excel (which is actually VBA) doing whatever I'm looking to automate. That gives you the shell of the code you need in Access. You always need to add the Excel object to the beginning, but like I said it gives you the guts of the code.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #20
    Collins is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    107
    Quote Originally Posted by pbaldy View Post
    A trick I've often used is to record a macro in Excel (which is actually VBA) doing whatever I'm looking to automate. That gives you the shell of the code you need in Access. You always need to add the Excel object to the beginning, but like I said it gives you the guts of the code.
    Now Macros I have can do... So you're saying record the formatting in access as a macro then take the code that was written to do that and copy it over to the VBA editor in Access? What additional code is needed to get access to read the formatting code after my "SELECT * FROM QueryExportData" statement?

  6. #21
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No, I'm saying record a macro in Excel then adapt the code for use in Access. If I didn't know how to bold and underline a cell, I'd record a macro doing that and then examine the code that Excel created.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #22
    Collins is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    107
    Quote Originally Posted by pbaldy View Post
    No, I'm saying record a macro in Excel then adapt the code for use in Access. If I didn't know how to bold and underline a cell, I'd record a macro doing that and then examine the code that Excel created.
    Oh gotcha...

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 08-13-2014, 11:07 AM
  2. Replies: 1
    Last Post: 02-19-2014, 11:26 AM
  3. Replies: 1
    Last Post: 11-16-2013, 09:01 AM
  4. Replies: 3
    Last Post: 09-08-2013, 08:50 AM
  5. Exporting To Excel And Formatting, Office 2010
    By DazJWood in forum Programming
    Replies: 2
    Last Post: 11-23-2011, 08:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums