Solved

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

Posted on 2013-12-03
4
1,269 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
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

821 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