Solved

Jet OLEDB error! Viewing your linked MS Excel worksheeet was lost

Posted on 2013-12-03
4
1,326 Views
Last Modified: 2013-12-04
Hi,

I'm trying to query data from my two sheets in the workbook and save the result on the third sheet.  But I keep getting the following error:
Run-time error '-2147467259 (80004005)':
The connection for viewing your linked Microsoft Excel worksheet was lost.

The odd thing is, I use this code for almost all of my macros and I've NEVER had any issues.  And for some reason it even ran once before!  I don't know what's causing it.  Could anybody help?

Dim objCon1 As ADODB.Connection, dataSQL As String, dataRS1 As ADODB.Recordset

Set wb = ThisWorkbook
Set P_ws = wb.Worksheets("SECDATA")
Set PL_ws = wb.Worksheets("PLDATA")
Set output_ws = wb.Worksheets("Output")

output_ws.Cells.ClearContents

Set objCon1 = New ADODB.Connection
objCon1.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & ThisWorkbook.FullName & ";" & _
    "Extended Properties=""Excel 8.0;HDR=Yes;"";"

    dataSQL = "SELECT distinct p.COPYID as ID, d.* " & _
                "FROM [PLDATA$] as p, [SECDATA$] as d " & _
                "WHERE p.[CCodes] = d.TICKER "
    
    Set dataRS1 = New ADODB.Recordset
    dataRS1.Open dataSQL, objCon1
    y = 1
    For Each fld In dataRS1.Fields
        output_ws.Cells(1, y).Value = fld.Name
        y = y + 1
    Next
    output_ws.Cells(2, 1).CopyFromRecordset dataRS1

    objCon1.Close
    Set objCon1 = Nothing
    Set dataRS1 = Nothing

Open in new window

0
Comment
Question by:iamnamja
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Assisted Solution

by:andrew_man
andrew_man earned 250 total points
ID: 39694208
Can post your file here?
0
 
LVL 4

Expert Comment

by:andrew_man
ID: 39694515
File path incorrect!  Please dump the error screen to here.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 250 total points
ID: 39694873
Which version of Excel is it? If 2007 or later, what format is the workbook - .xls, .xlsm, .xlsb?
0
 

Author Comment

by:iamnamja
ID: 39695527
Hey guys,

I found the issue.  There was another sheet where I was linking a text file (PL_ws), and when I tried the above code for some reason it was giving me an error.

What I did to get around this was to copy the results of the data that was linked to another sheet first, and query it through there.  Thanks for all your help!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question