Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-03
4
Medium Priority
?
1,380 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 1000 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 1000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

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…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

721 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