Results 1 to 2 of 2
  1. #1
    JimReid is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2022
    Location
    Erial , New Jersey
    Posts
    30

    Excel confused in Access VBA

    I have an interesting problem. I'm running a SQL query and then populating an Excel Spreadsheet(s). After completing the reading of the SQL output I do some calculation on the spreadsheets and then give the operator the option to save or not the spreadsheet. Then I return to the form that ran the VBA code. The problem is Excel doesn't seem to unload and clear memory. If I enter the options to run another extract I get an error on the Activesheet.Name!!



    The error is "run-time error '91': Object variable or With block variable not set"

    The first time through everything is fine. The 2nd time is when I get the error.

    On opening I have the following:'
    Set XL = New Excel.Application
    XL.Visible = True
    Set wb = XL.Workbooks.Add
    Set WKS = wb.Worksheets(1)

    And on closing I have the following:
    Set wb = Nothing
    XL.Quit
    Set XL = Nothing


    I've checked the Task Manager and apparently Excel is gone at the end of the first pass.
    It appears that it thinks that Excel is still there or it isn't setting up a new workbook for the second pass. I'm not sure which.

    Any help would be appreciated. The coding is very long and too big to post it all here but the app seems to be working fine other than running it multiple times in a row.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Can be caused by unqualified references to Excel objects. This can happen with automation of any app (Excel, Word, Outlook, etc). Review https://stackoverflow.com/questions/...15517#71015517

    Show the reset of procedure code if you need more help.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 12-15-2017, 08:09 PM
  2. Very confused about restricting access to select data in a table
    By cantankerousoldyankee in forum Security
    Replies: 4
    Last Post: 09-20-2014, 12:25 AM
  3. Access 2003 or access 2007 Confused?
    By fazee in forum Access
    Replies: 1
    Last Post: 12-02-2012, 06:30 AM
  4. Replies: 2
    Last Post: 10-25-2012, 03:51 AM
  5. New at access and confused
    By darlaj5 in forum Access
    Replies: 4
    Last Post: 05-05-2011, 09:46 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