+ Reply to Thread
Results 1 to 7 of 7

Query on Excel sheet returns error, how to prevent error message

  1. #1
    Registered User
    Join Date
    05-02-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    23

    Question Query on Excel sheet returns error, how to prevent error message

    I tried to use VBA to refresh a query (on another excel spreadsheet) wit the code below:


    Application.ScreenUpdating = False
    On Error Resume Next

    Selection.ListObject.TableObject.Refresh
    ActiveWorkbook.Connections("Query - tbl_PRODLIST").Refresh

    Application.ScreenUpdating = True



    If the workbook is opened of a computer that does not have the spreadsheet from which the refresh is necessary, the refresh should not return an error but continue without refreshing the query. How can I prevent the error message ("Connection can not be refreshed") from appearing on screen?
    Error checking is not my strongest point in VBA.

    Thank for any help regarding this issue.

    Ron

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Query on Excel sheet returns error, how to prevent error message

    Try adding in DisplayAlerts
    Please Login or Register  to view this content.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    05-02-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Query on Excel sheet returns error, how to prevent error message

    Hi dflak,

    Tried that before but I still get the same error message; a [Data source error}.

    Ron

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Query on Excel sheet returns error, how to prevent error message

    OK, try this. Instead of continuing through the code, skip over it.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-02-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Query on Excel sheet returns error, how to prevent error message

    Hi dflak,

    This does not work either, still get the same [Data source error]. The second line causes the error and returns with a dialog window with the [Data source error].

  6. #6
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Query on Excel sheet returns error, how to prevent error message

    Hmmm, That code worked for me. It ran quietly and I know I don't have a connection with that name . Here is a test program.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    05-02-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    23

    Re: Query on Excel sheet returns error, how to prevent error message

    Hi dflak,

    I tried to implement your code example but this is the error message I get:

    Attachment 622623

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Scripting error message pops up whenever excel web query is executed
    By kyk8898 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-13-2018, 09:32 AM
  2. Can't prevent compile error message.
    By crabman9 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-16-2017, 07:09 AM
  3. Excel 2007: A Macro created to run Solver returns error message
    By chrys_t in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2014, 08:45 PM
  4. SQL Query with Excel VBA Returns General ODBC Error when Using Variables
    By Dirigo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-30-2011, 03:05 AM
  5. How to prevent error message during macro
    By excelnut1954 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2006, 10:10 AM
  6. Replies: 0
    Last Post: 06-06-2005, 10:05 AM
  7. Prevent Error Message
    By phil in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-26-2005, 03:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1