Results 1 to 6 of 6
  1. #1
    is49460 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    40

    How to force to continue vba execution after a function call


    Hello,

    I have the following dilemma: I have a database and an excel report with a pivot table that feeds from some tables in that database. I refresh that pivot table daily to obtain new data from the database. I want to create a VBA function in the database to open the excel report to refresh it automatically. Everything works fine (opening excel, running excel’s functions, etc). The problem I am facing is that when function attempts to refresh pivot in excel the pivot cannot access the table in the database because the database is in locked state during execution of the VBA. I hope that makes sense... Is there a way to force VBA to continue code execution (and exit out of function) after making a call to excel's function? Any suggestions are appreciated.

    Thanks!!

  2. #2
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    It might help if you post your code.

    If you are linked to a table in Access from Excel 2007 I'm sure there is an option for Excel to refresh itself after a set number of minutes. Might be worth checking this out.

  3. #3
    is49460 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    40
    Here is a simplified code:

    Code in the database:
    Dim xlApp As Object
    Dim xlWb As Object
    Dim xlWS As Worksheet
    Dim strSheet As String
    Dim sFullPath As String

    sFullPath = "c:\MyExcelFile.xls"
    Set xlApp = CreateObject("Excel.Application")
    Set xlWb = xlApp.Workbooks.Open(sFullPath, True)
    xlApp.Visible = True

    xlApp.Run "'MyExcelFile.xls'!RefreshReport"

    Code in Excel in RefreshReport Sub:

    Sheets("Report").Select
    ActiveSheet.PivotTables("PivotTable1").PivotCache. Refresh

    The external source data for PivotTable1 is a table in the database

    Thanks!!!!

  4. #4
    is49460 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    40
    I guess one solution is to rewrite excel code to access, but I wanted to avoid doing that due to amount of code and there is a need to run the code from excel at times...

  5. #5
    SoftwareMatters is offline Access VBA Developers
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    274
    Have you looked at the auto refresh within Excel?

  6. #6
    is49460 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2010
    Posts
    40
    Quote Originally Posted by SoftwareMatters View Post
    Have you looked at the auto refresh within Excel?

    Only admin should be able to do the refresh. Daily refresh is not always consistent, depending on other factors. I don't think autorefresh would work, but thanks for the suggestion!

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

Similar Threads

  1. Force users to log off
    By Bruce in forum Security
    Replies: 8
    Last Post: 01-10-2013, 07:03 PM
  2. Pausing macro execution
    By lupis in forum Programming
    Replies: 3
    Last Post: 06-28-2010, 12:46 AM
  3. Replies: 4
    Last Post: 11-06-2009, 09:51 AM
  4. How to force carriage return between strings?
    By Divardo in forum Reports
    Replies: 1
    Last Post: 05-21-2009, 10:50 AM
  5. Force writing from the right in a field?
    By Looping in forum Forms
    Replies: 0
    Last Post: 01-23-2006, 03:03 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