Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42

    Transfer new data to Excel not working

    I am trying to transfer data from Access (latest version) to Excel. The transfer has worked for a long time and works OK until I add two fields to the source query (q_Excel_Export_2). The message I get is shown below. I just can't figure it out.

    The message:
    RUN TIME ERROR '3420'
    OBJECT INVALID OR NO LONGER SET

    The stop occurs at the third line.



    Dim exfile As String
    exfile = CurrentProject.Path & "" & .ExcelFile
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "q_Excel_Export_2", exfile, -1

    Any help much appreciated

  2. #2
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 10 Office 365
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,536
    An alternative is to import the query to Power Query and then close and load the data to excel.

    Power Query Access database connector - Power Query | Microsoft Docs

  3. #3
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    The xfer of data to excel is only a small part of the program. This is an item for sailboat downwind phrf (seconds per mile) ratings. Lots of other things, so it has to be just select the boat and proceed.. It is just one of the items on the form. I will look at the data and see if possible to use.
    Thanks much for replying so soon.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,285
    Anything actually in ExcelFile?
    Walk through your code inspecting variable values.
    Debug.Print them if need be.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,235
    CurrentProject.Path does not include the backslash so unless you have it in the textbox that has the file name you need to include it:
    Code:
    Dim exfile As String
    exfile = CurrentProject.Path & "\" & Me.ExcelFile 'assumes you have a textbox on the form to hold the Excel file name
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "q_Excel_Export_2", exfile, True
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    Quote Originally Posted by Welshgasman View Post
    Anything actually in ExcelFile?
    Walk through your code inspecting variable values.
    Debug.Print them if need be.
    The code has been working for a long time with lots of data sent from Access to Excel. Problem comes from adding two new fields. I just can't make it work.

  7. #7
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    I do have the backslash included. The thing that is driving me crazy is that the program has worked for years. Somehow, adding two fields to Access just won't work! I have changed the query that exports the data, but still won't work.

  8. #8
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    OK, if the export worked until you modified the query, it has to be something related to the query.
    You have not posted the SQL of the query BEFORE the change, nor the SQL of the query AFTER the change.

    What are the two "fields" (columns) added to the query? Did you add two fields to a table and include the new fields in the query?

    If you open the query "q_Excel_Export_2", do you get the expected results?

  9. #9
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    Thanks for reply.
    I did check and the two new fields are there and exactly where they are supposed to be.

    The alarm message is:
    ERROR 3027
    Cannot Update. Data Base or Object is read only.

    When click on error message, takes me to this portion of the code that exports data to excel.
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "q_Excel_Export_2", exfile, -1

    Driving me crazy. Without the two new fields, it has worked perfectly for years. I am able to manually export to a new excel file. I will try to append and get back to you.

  10. #10
    ssanfu is offline Master of Nothing
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If you open the query "q_Excel_Export_2", do you get the expected results?


    Please post the SQL of the query BEFORE the change and the SQL of the query AFTER the change.

  11. #11
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    Quote Originally Posted by ssanfu View Post
    If you open the query "q_Excel_Export_2", do you get the expected results?


    Please post the SQL of the query BEFORE the change and the SQL of the query AFTER the change.
    Here are the two. Hope they show you something. The excel file with or without the new fields works fine with the original query. Sorry I took so long to respond. Had some other things I had to do. Appreciate your help.

    Query with two more fields that won’t append to excel file. Two added fields are
    SELECT TblBoatData.BOAT_NAME, TblBoatData.BOAT_TYPE, TblBoatData.i, TblBoatData.hdsail AS [LP_%], TblBoatData.LP, TblBoatData.HSGIRTH AS HS_Girth, TblBoatData.ISP, TblBoatData.J, TblBoatData.JSP, TblBoatData.P, TblBoatData.E, TblBoatData.hb AS MGT, TblBoatData.MGU, TblBoatData.MGM, IIf([SYM_SPIN]="yes","Y","N") AS [sym?], TblBoatData.SL, TblBoatData.SSMG, TblBoatData.SSF, TblBoatData.jsp AS SPL, IIf([ASYM_SPIN]="YES","Y","N") AS [Asym?], TblBoatData.SLU, TblBoatData.SLE, TblBoatData.ASMG, TblBoatData.ASF, TblBoatData.SPRIT AS SpritLength, TblBoatData.[Articulate Spinnaker] AS Artic, TblBoatData.PY, TblBoatData.EY, 0 AS hdsa, 0 AS sa_M, 0 AS SA_s, 0 AS SA_a, TblBoatData.LOA, TblBoatData.LWL, TblBoatData.Maxbeam AS Beam, TblBoatData.Max_draft AS Draft, TblBoatData.Displacmt AS Disp, T_DW_BallastFactor.BallastMovType AS MovBallast, TblBoatData.profile, TblBoatData.prop_type AS Prop, TblBoatData.comshift, TblBoatData.LH, TblBoatData.BO, TblBoatData.X, TblBoatData.h, TblBoatData.SO, TblBoatData.Y, TblBoatData.irc_wt AS IRCwt, TblBoatData.ORR_L AS ORRratedL, TblBoatData.disp_orr AS DispORR, TblBoatData.Com_l, TblBoatData.comdispl AS Com_Displ, TblBoatData.IDboat
    FROM TblBoatData INNER JOIN T_DW_BallastFactor ON TblBoatData.BALAST_MOV = T_DW_BallastFactor.IDballast
    WHERE (((TblBoatData.IDboat)=[Forms]![FrmMemberScreen].[form].[IDboat]));

    Query that works
    SELECT TblBoatData.BOAT_NAME, TblBoatData.BOAT_TYPE, TblBoatData.i, TblBoatData.hdsail AS LP, TblBoatData.ISP, TblBoatData.J, TblBoatData.JSP, TblBoatData.P, TblBoatData.E, TblBoatData.hb AS MGT, TblBoatData.MGU, TblBoatData.MGM, IIf([SYM_SPIN]="yes","Y","N") AS [sym?], TblBoatData.SL, TblBoatData.SSMG, TblBoatData.SSF, TblBoatData.jsp AS SPL, IIf([ASYM_SPIN]="YES","Y","N") AS [Asym?], TblBoatData.SLU, TblBoatData.SLE, TblBoatData.ASMG, TblBoatData.ASF, TblBoatData.SPRIT AS SpritLength, TblBoatData.[Articulate Spinnaker] AS Artic, TblBoatData.PY, TblBoatData.EY, 0 AS hdsa, 0 AS sa_M, 0 AS SA_s, 0 AS SA_a, TblBoatData.LOA, TblBoatData.LWL, TblBoatData.Maxbeam AS Beam, TblBoatData.Max_draft AS Draft, TblBoatData.Displacmt AS Disp, T_DW_BallastFactor.BallastMovType AS MovBallast, TblBoatData.profile, TblBoatData.prop_type AS Prop, TblBoatData.comshift, TblBoatData.LH, TblBoatData.BO, TblBoatData.X, TblBoatData.h, TblBoatData.SO, TblBoatData.Y, TblBoatData.irc_wt AS IRCwt, TblBoatData.ORR_L AS ORRratedL, TblBoatData.disp_orr AS DispORR, TblBoatData.Com_l, TblBoatData.comdispl AS Com_Displ, TblBoatData.IDboat
    FROM TblBoatData INNER JOIN T_DW_BallastFactor ON TblBoatData.BALAST_MOV = T_DW_BallastFactor.IDballast
    WHERE (((TblBoatData.IDboat)=[Forms]![FrmMemberScreen].[form].[IDboat]));

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    The only object involved with transferspreadsheet is the query (don't know if transferspreadsheet invokes objects behind the scenes)

    time for some experimenting to determine what is causing the error - remove the 2 columns from q_Excel_Export_2 and run your code - does it run OK or do you get an error

    assuming no error, add back one of the columns and repeat

    assuming no error remove the first column and add the other column

    assuming no error add back the first column (i.e. back to the original)

    at least should determine if the error is actually due to the two fields or something else.



    Other things to try
    - compact/repair
    -decompile/recompile

    -presume you have option explicit at the top of all modules and code compiles without error

    -you don't need the -1 in the end parameter - the value is ignored when exporting




  13. #13
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,706
    I tried defining and using a string with name ending in _% and got errors even with brackets.

    Try changing TblBoatData.hdsail AS [LP_%] to TblBoatData.hdsail AS LP_Pct

  14. #14
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,845
    I tried defining and using a string with name ending in _% and got errors even with brackets.
    one more for the pot - ideally should never use non alphanumeric characters in field names, particularly those that can be used by sql itself

  15. #15
    dmgg is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Feb 2014
    Posts
    42
    Quote Originally Posted by davegri View Post
    I tried defining and using a string with name ending in _% and got errors even with brackets.

    Try changing TblBoatData.hdsail AS [LP_%] to TblBoatData.hdsail AS LP_Pct

    I finally got a chance to try it. Unfortunately, still won't work.

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

Similar Threads

  1. Automatic transfer data from Access to Excel
    By Sarabjit in forum Access
    Replies: 11
    Last Post: 10-20-2014, 07:27 PM
  2. Replies: 2
    Last Post: 10-16-2014, 12:08 PM
  3. Replies: 5
    Last Post: 06-12-2011, 03:58 PM
  4. How to transfer data from excel to Access?
    By mit in forum Import/Export Data
    Replies: 4
    Last Post: 06-11-2011, 05:39 PM
  5. Transfer data to excel
    By John Southern in forum Import/Export Data
    Replies: 5
    Last Post: 06-11-2010, 09:26 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