PC Review


Reply
Thread Tools Rate Thread

ADO Automation Error

 
 
EricG
Guest
Posts: n/a
 
      18th Feb 2010
I have a very simple Workbook_Open routine that is supposed to grab some data
from another Excel workbook. I'm not doing anything with the data yet,
because I can't get past the automation error I'm getting. The error is:

"The Microsoft Jet database engine could not find the object 'Sheet2$'.
Make sure the object exists and that you spell its name and the path name
correctly."

Sheet2 definitely exists and there is data on it. Does anyone see an error
in my code below, or is there some other source for the error. The error
occurs on the line marked with **************.

Thanks,

Eric

Option Explicit

Private Const masterFile = "D:\data\thisUser\Desktop\MasterFile.xls"

Private Sub Workbook_Open()
Dim conData As New ADODB.Connection
Dim rstAssigns As New ADODB.Recordset
'
Dim intCount As Integer
Dim strSelect As String
Dim strResults As String
'
With conData
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & masterFile & _
";Extended Properties=Excel 8.0;Persist Security Info=False"
.ConnectionTimeout = 30
.Open
End With
'
strSelect = "SELECT * FROM [Sheet2$]"
'
On Error GoTo Oops
'
rstAssigns.ActiveConnection = conData
rstAssigns.Source = strSelect
rstAssigns.Open '***************** This does not work.

On Error GoTo 0
'
Do While Not rstAssigns.EOF
For intCount = 0 To rstAssigns.Fields.Count - 1
' Do stuff with the data here...
Next
rstAssigns.MoveNext
Loop
'
conData.Close
Exit Sub
'
Oops:
Debug.Print "Oops! Something went wrong."
Debug.Print Err.Description
End Sub
 
Reply With Quote
 
 
 
 
arjen van der wal
Guest
Posts: n/a
 
      18th Feb 2010
Hi Eric,

I have a spreadsheet with a similar routine. In the section where you have
the error occur I have mine setup as follows (I've used the names from your
example):

rstAssigns.Open strSelect, conData, adOpenStatic, adLockReadOnly, adCmdText

Your sheet name reference does look correct.

Here's the whole routine as I had set it up. It's structured a bit different
from yours, but that shouldn't be an issue.

Sub QueryExcelSupersheet()

'create the connection string
Dim ConnectionString As String

ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" & _
"Data Source=K:\ADO\SUPERSH.xls;" & _
"Extended Properties=Excel 8.0;"

'create the sql query
Dim MyQuery As String

MyQuery = "SELECT * " & _
"FROM [Today$] "

'create the recordset
Dim MyRS As ADODB.Recordset
Set MyRS = New ADODB.Recordset

'open the recordset
MyRS.Open MyQuery, ConnectionString, adOpenStatic, adLockReadOnly,
adCmdText

Sheets("xl data").Activate
ActiveSheet.Range("A1").CopyFromRecordset MyRS

MyRS.Close
Set MyRS = Nothing

End Sub

Hopefully this helps.
 
Reply With Quote
 
EricG
Guest
Posts: n/a
 
      18th Feb 2010
Thank you for your reply.

I took your code exactly, changed the file path and name to mine, and
changed the sheet name to mine. I get the same error that I got with my
code. :-(

It still bombs on the "open" statement, complaining the it can't find the
object "Sheet2$".


"arjen van der wal" wrote:

> Hi Eric,
>
> I have a spreadsheet with a similar routine. In the section where you have
> the error occur I have mine setup as follows (I've used the names from your
> example):
>
> rstAssigns.Open strSelect, conData, adOpenStatic, adLockReadOnly, adCmdText
>
> Your sheet name reference does look correct.
>
> Here's the whole routine as I had set it up. It's structured a bit different
> from yours, but that shouldn't be an issue.
>
> Sub QueryExcelSupersheet()
>
> 'create the connection string
> Dim ConnectionString As String
>
> ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" & _
> "Data Source=K:\ADO\SUPERSH.xls;" & _
> "Extended Properties=Excel 8.0;"
>
> 'create the sql query
> Dim MyQuery As String
>
> MyQuery = "SELECT * " & _
> "FROM [Today$] "
>
> 'create the recordset
> Dim MyRS As ADODB.Recordset
> Set MyRS = New ADODB.Recordset
>
> 'open the recordset
> MyRS.Open MyQuery, ConnectionString, adOpenStatic, adLockReadOnly,
> adCmdText
>
> Sheets("xl data").Activate
> ActiveSheet.Range("A1").CopyFromRecordset MyRS
>
> MyRS.Close
> Set MyRS = Nothing
>
> End Sub
>
> Hopefully this helps.

 
Reply With Quote
 
EricG
Guest
Posts: n/a
 
      18th Feb 2010
I hate myself sometimes.

I found the problem - password protection. I removed it, and the code works
like it should.


"joel" wrote:

>
> Does the workbook have a "sheet2" (no dollar sign)? The dollar sign at
> the end of the sheet name is required using the ADO method because
> worksheets have a hidden dollar sign in the sheet name that you don't
> normnally see.
>
>
> --
> joel
> ------------------------------------------------------------------------
> joel's Profile: 229
> View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=180404
>
> Microsoft Office Help
>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent!!! Run-time error '-2147024770 (8007007e)' Automation error lakshmisaran@gmail.com Microsoft Excel Programming 3 28th May 2008 04:51 AM
Run-Time error '-2147417848 (80010108)': Automation error The object invoked has disconnected from its clients SeangSTM Microsoft Excel Programming 0 28th Apr 2006 07:46 PM
Run-Time error '-2147417848 (80010108)': Automation error The object invoked has disconnected from its clients SeangSTM Microsoft Excel Programming 0 28th Apr 2006 07:45 PM
Runtime Error 2147221231 automation error ClassFactory can't supply requested cl Elaine Windows XP General 0 4th Sep 2003 04:11 AM
error '800706d5'----- Automation error The security context is invalid Elsa Microsoft Windows 2000 Security 0 25th Jul 2003 10:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:39 AM.