Results 1 to 12 of 12
  1. #1
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56

    Refresh excel query through access

    I am trying to refresh an excel sheet with access. The excel sheet contains a connection string to a database and has SQL as the Command Text. Now below is my vba code in access, when I run it, the excel file opens and I am presented with the box to enter the connection parameters. After entering, a message pops up saying that "A pending refresh operation will be cancelled. What am I doing wrong? All I want is for the workbook to auto-refresh, then save and close.



    Code:
    Public Function refreshMedData()
    
    Set xlapp = CreateObject("Excel.Application")
    
    xlapp.Visible = True
    
    Set xlWrkBk2 = xlapp.Workbooks.Open("M:\BSC Benefits\PMO\Reports\Med Data Extract PROD.xlsx")
    
    xlWrkBk2.Unprotect
    xlWrkBk2.UnprotectSharing
    xlWrkBk2.Activate
    
    ActiveWorkbook.RefreshAll
    DoEvents
    
    xlWrkBk2.Save
    
    xlWrkBk2.Close True
    
    MsgBox "Done. Med Data Refreshed"
    
    End Function

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You are using Access to link to Excel to link to SQL?
    If you are in access, just link directly to SQL, skip the middleman.

  3. #3
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    Yes, I have the code tied to a button in access. When I click the button I want it to open and refresh the excel file and then close it. I still need to prompt for connection password. How can I do this?

  4. #4
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    I am not sure what you mean by link directly to the sql? I do not want to physically store the table as the sql produces 650,000 rows.

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I am also confused. Why is Excel involved? What kind of db is Excel linking to - SQL? Why don't you have Access link to that db?

    Excel has limit of 1,048,576 rows. You are at 650,000. Will you outgrow Excel? Is this sheet slow?
    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.

  6. #6
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    I have the sql in excel. I was previously running the "Refresh All" from excel to run the sql and refresh the data. I have an access DB which links to the excel spreadsheet. There are secondary analytical process and reports that runs in access after the data is refreshed in excel. So I thought that it would be easier if I could just do the refresh from access so that I do not need to go to excel first.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What do you mean by 'have the sql in excel' - are you linking to an SQL database? Is that why there is a password issue? I still don't understand why Access cannot link directly to that db.

    Maybe this is relevant to your issue http://stackoverflow.com/questions/2...l-finishes-vba
    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.

  8. #8
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    It is an oracle DB. The access database itself is already 1.4 GB so I do not want to make it any larger by storing the 650,000 rows in a physical table. That is why I came up with the link to excel idea. Below is screen of how I am running data in excel. If there is a way to do the same idea in access as in the excel screenshot then I would like to know. Otherwise I need to know how I can run the excel SQL through access vba using code similar to what I first posted.
    Attached Thumbnails Attached Thumbnails excel con.JPG  

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What do you mean by 'do not want to store to a physical table'? The data is already in a physical table in Oracle. Access would merely have a link to that table. Excel has a link, why not link from Access?

    Did the referenced web page 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.

  10. #10
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    My SQL joins five tables together. I would have to link to all five tables. Another option would be to store the data physically in its own separate access database. Then just link to that.

  11. #11
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Quote Originally Posted by gammaman View Post
    My SQL joins five tables together. I would have to link to all five tables. Another option would be to store the data physically in its own separate access database. Then just link to that.
    As you stated yourself - LINK from Access, not STORE in Access. So why not link directly from Access as two persons before already asked?

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Right, why not link to five tables? This is the easiest and most efficient approach. Eliminate Excel.
    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: 6
    Last Post: 05-03-2014, 08:53 AM
  2. Refresh Password protected excel from access
    By ragsgold in forum Programming
    Replies: 3
    Last Post: 01-16-2013, 06:20 PM
  3. Replies: 3
    Last Post: 08-06-2012, 01:12 AM
  4. Access 2010 Refresh VS Refresh ALL
    By Snwboarder1982 in forum Access
    Replies: 1
    Last Post: 09-09-2011, 04:07 PM
  5. Error excel refresh from access
    By goyal in forum Access
    Replies: 0
    Last Post: 06-10-2009, 10:59 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