Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 53
  1. #16
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    In the attached two zipped files is my working db and the other is the Excel file that I am trying to send Access data the table to.

    It generates an error that says it cannot find that Excel *.xlsm file. I cannot understand since the file is in the correct directory
    with the correct path and correct name. The file extension that I used is *.xlsm. It is a macro enabled file. But it still says that it cannot find the
    file.

    What is going on. It seems that everything is fine.

    Any help appreciated. Thansk in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  2. #17
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I do not what was casing it to crash on the VBA line that connected with the Excel file, but it did.

    It just does not seem to be e crashing there now; it is crashing on the line below the line where it
    formerly crashed. The attached pdf file shows a Snagit screen shot.

    Now I have also included the MS Access files that contains the VBA code. I am just not sure what is causing the crash.

    What exactly causes this crash?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  3. #18
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    When you post the screenshots, they only indicate WHERE the error occurred, not what the error is.
    Please tell us what the error message says (doesn't have to be a screenshot), because without it we can only guess.

  4. #19
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    From post #16 -

    Your VBA code has this : x1.Workbooks.Open ("C:\Users\james.yunker\Desktop\TestBook.xlsx"), with the file name in red,

    but the zipped file you posted is called testing.xlsm.

    Obviously one of them isn't right, and I suspect it is your VBA. Among other things, is your user name James.Yunker?

  5. #20
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    That was the first thing that I looked at and when I changed the filename in the VBA to match the filename in the directory it did not seem to matter.

    It is now failing on the line after x1.Workbooks.Open ("C:\Users\james.yunker\Desktop\TestBook.xlsx"), with the file name in red,

    this one. I thought the snagit shot did contain error description.

    That is also my username of an employee that long ago left my organization.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  6. #21
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Here it is again. The program showed a runtime error when it hit the line shown in the snagit picture.

    It has happened before.

    I just do not what is causing it and I am asking for assistance.

    If it is obvious, well it is not to me.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  7. #22
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    It's not obvious to me, either. I downloaded your database and the Excel file, and it ran without an error (after I changed the file location).
    The only thing I can think of is that you have a wrong or missing reference. Can you post a screencap of the references you have set in your Database?

    While in any code module, Select Tools - References, and you will see a dialog with the list of references.

    I can't tell what your references are, because my Access 2016 automatically resets the list.

  8. #23
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I was thinking that too. I was just unsure as to how to check it.

    Respectfully,

    Lou Reed
    Attached Thumbnails Attached Thumbnails Capture.jpg  

  9. #24
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I think that I found it. The line in my code:

    Set ws = xl.ActiveWorkSheet.Sheets.Add

    should be

    et ws = xl.ActiveWorkbook.Sheets.Add

    This correction also compiles and is i believe the correct way to put it in.

    I just need now to hook up the selection of the table to this code.

    I know that it is this line that must be chnaged:


    Set rs = db.OpenRecordset("Table1")

    i am just sure what to put in instead of Table1.

    Ny help apreciated. Thanks in advance.


    Respectfully,

    Lou Reed

  10. #25
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    In the zipped file which contains my current db, there is a difference in the action of the two subs that import MS Access Table1 They are shown in the screen capture1 and capture2.

    The first column in the more generalized code on puts a number in the first row oftestbook.xlsx, but nowhere else and it i wrong anyway.

    If the second sub is a true generalization then it should copy the Access Table1 exactly as it does in the specific cr less generalized code.

    Where is the inconsistency in the code? Any help appreciated. thanks in advance.

    Respectfully,

    Lou Reed
    Attached Thumbnails Attached Thumbnails Capture1.GIF   Capture2.GIF  
    Attached Files Attached Files

  11. #26
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I made a mistake. the error was the extra column and the presence of a 1 in it. It only shows up in the generalized code n the first row. Nowhere else.

    How do i get rid of it.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  12. #27
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The code is working exactly as it should; the Excel spreadsheet matches the data in Table1. If you look at Table1, the first field is Called ID, and only record 1 has a value in it (The "1"). If you want that field not to be transferred to the spreadsheet, the easiest solution is to delete that field from the Table1 structure. You could also delete the column from the Excel spreadsheet after the export - no difference.

  13. #28
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, but why does it not also transfer this when I do the non-general Excel transfer? It seems to leave it off.

    I have included a modified version of the Access program, plus the output on both Subs on Excel sheets. The Excel sheets should be the same. They are close, but they are not the same.

    ignore the fact that they start on different rows, that should be unimportant.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  14. #29
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Youe subs Sub btnExportExcel_Click and ExportTabletoExcel_Click are different.

    The first is not generalized for any table - it transfers only 4 fields, and refers to them by name. It also does not transfer the field names as column headers. The table field ID is not used.

    The second is generalized for any table. It determines how many fields there are, and names of the fields from the recordset. It then transfers the names of the fields as column headers (if they are in row 1), followed by the data. It works for any table because it does not refer to recordset fields by name, only by field index number.

    Different subs, different results.

  15. #30
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I am going to use the generalized VBA code sub. I removed the specific VBA subs and only worried about the generalized code. Now I have got an error:

    RunTime Error 91
    Object variable or with block variable not set.

    See pdf attachments. It says that a variable must be set, but I thought everything was alight.

    I have included two pdf and a zipped files of the db. What is casuing this?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

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

Similar Threads

  1. Replies: 1
    Last Post: 04-17-2016, 02:33 PM
  2. Automatic transfer data from Access to Excel
    By Sarabjit in forum Access
    Replies: 11
    Last Post: 10-20-2014, 07:27 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 Access into Excel problem
    By BorisGomel in forum Programming
    Replies: 4
    Last Post: 05-23-2011, 02:47 PM

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