Results 1 to 12 of 12
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    VBA code in Excel will not comoile

    In the attached MS Access 2010 db, I have db with some additional code. I wanted to add a browse button to the form that exports an MS Access table back to
    MS Excel 2010.

    I have a working set of code that allows one to select a file to import an MS Excel table into MS Access. It works.

    I just recycled the VBA code and put in in the VBA code area for the form to export Access tables back to Excel.

    It is the same code! I changed the file and the sub name to avoid any ambiguity, but besides that it is the same code.



    However, it does not compile it throws an error. I am not sure why.

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Click image for larger version. 

Name:	dblError.png 
Views:	16 
Size:	16.7 KB 
ID:	31529
    you have
    btnBrowse2_Click INSIDE btnBrowse2_Click

    remove the outer one. (and the END SUB)

  3. #3
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, I will give it a try. Thanks you.

    Respectfully,

    Lou Reed

  4. #4
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    i tried that and it seemed to not complain. Sorry about being so clumsy before.

    My concern now is the new error message, that I get when I try to compile.

    I have uploaded a zipped version of this db, plus a screen capture of the error when compiling.

    It did not require me to rename the Sub since they are on different forms so I just kept the same name and the same code.

    What is the cause of the error? Any help appreciated.

    Respectfully,

    Lou Reed
    Attached Thumbnails Attached Thumbnails Capture.PNG  
    Attached Files Attached Files

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    it works fine for me.

  6. #6
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Well, I cannot explain the error message. I will look into it.

    I am correct in assuming that I did not have to change the SUB name since I am on a different form?

    Respectfully,

    Lou Reed

  7. #7
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Well, I have tried it on two different platforms and it does not compile. It still gaga on that line.

    MetxtFileName = item

    but only on the form for exporting MS Access table to Excel. Where is that file identified or defined?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The sample works fine for me too. You appear to have the code above in the export form, which does not have that textbox. The import form does.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    You got me. I do not see what is missing in the export form's code.

    Respectfully,

    Lou Reed

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    In the sample, there is no code behind the browse button on the export form. In your picture above, you appear to have it there. The same code in the export form would throw that error, because there is no textbox named "txtFileName" on the export form.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    Okay, I see your point. Actually, I have created code for like this many times and I am surprised at myself.

    I have one question. How did you find this out? It seems awfully subtle. Did you just do it by inspection?

    Respectfully,

    Lou Reed

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    The compile error is telling you it can't find it, so it was my assumption out of the gate. Based on your description and the picture above, I saw you were putting it on a form that didn't have a control with that name. Looking at your sample confirmed it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 08-10-2015, 11:53 AM
  2. Add VBA code to an Exported Excel Workbook
    By gasmaskman in forum Programming
    Replies: 13
    Last Post: 02-11-2014, 10:00 AM
  3. VBA code to export from Access to Excel
    By DATADUDE28 in forum Access
    Replies: 1
    Last Post: 11-03-2012, 01:39 PM
  4. Calculating % in VBA Code For Excel
    By mkc80 in forum Access
    Replies: 1
    Last Post: 09-16-2012, 05:39 PM
  5. Excel code not working with Excel open
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 07-11-2011, 12:12 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