Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Table format - connection string problem

Hi

When I run the code below I get "External table is not in the expected
format" error at line rsData.Open sSQL, sConnect, adOpenForwardOnly,
adLockReadOnly, adCmdText

Option Explicit

Public Sub SelectFromAccess()

Dim rsData As ADODB.Recordset
Dim sPath As String
Dim sConnect As String
Dim sSQL As String

'Clear the destination worksheet
Sheets(1).UsedRange.Clear

'Get the database path (same as this workbook)
sPath = ThisWorkbook.Path

If Right$(sPath, 1) < "\" Then sPath = sPath & "\"

'Create the connection string
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath &
"Gemini.mdb;Extended Properties=Excel 8.0;"

'Build the SQL query
sSQL = "SELECT DISTINCT TurnoverPrecedingYears.[Nosnik kosztow - numer] FROM
TurnoverPrecedingYears;"

'Retrieve the data using ADO

Set rsData = New ADODB.Recordset
rsData.Open sSQL, sConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

If Not rsData.EOF Then
Sheets(1).Range("a1").CopyFromRecordset rsData
Else
MsgBox "No data located.", vbCritical, "Error!"
End If

rsData.Close
Set rsData = Nothing
End Sub



But if I delete Extended Properties=Excel 8.0 all is ok. Why is that? I run
the code above in excel 2007 but I'll also need to use it in excel 2003.

Kind regards
IgorM

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Table format - connection string problem

You're not connecting to a Workbook. You're connecting to an Access Database
therefore no need for ";Extended Properties=Excel 8.0;" When using ADO or
connecting to any database I recommend using Connection.udl to create the
connection string. Open Notepad, File, SaveAs, "Connection.udl".

use Connection.udl to build your connection string, Then right click
connection.udl,
open with notepad and copy your connection string.

"IgorM" wrote:

Hi

When I run the code below I get "External table is not in the expected
format" error at line rsData.Open sSQL, sConnect, adOpenForwardOnly,
adLockReadOnly, adCmdText

Option Explicit

Public Sub SelectFromAccess()

Dim rsData As ADODB.Recordset
Dim sPath As String
Dim sConnect As String
Dim sSQL As String

'Clear the destination worksheet
Sheets(1).UsedRange.Clear

'Get the database path (same as this workbook)
sPath = ThisWorkbook.Path

If Right$(sPath, 1) < "\" Then sPath = sPath & "\"

'Create the connection string
sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sPath &
"Gemini.mdb;Extended Properties=Excel 8.0;"

'Build the SQL query
sSQL = "SELECT DISTINCT TurnoverPrecedingYears.[Nosnik kosztow - numer] FROM
TurnoverPrecedingYears;"

'Retrieve the data using ADO

Set rsData = New ADODB.Recordset
rsData.Open sSQL, sConnect, adOpenForwardOnly, adLockReadOnly, adCmdText

If Not rsData.EOF Then
Sheets(1).Range("a1").CopyFromRecordset rsData
Else
MsgBox "No data located.", vbCritical, "Error!"
End If

rsData.Close
Set rsData = Nothing
End Sub



But if I delete Extended Properties=Excel 8.0 all is ok. Why is that? I run
the code above in excel 2007 but I'll also need to use it in excel 2003.

Kind regards
IgorM

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table Connection String - How to hide it? fijieddie Excel Discussion (Misc queries) 4 March 4th 09 03:46 AM
Pivot Table connection String Max Scott[_3_] Excel Programming 0 February 26th 09 10:33 AM
Chartspace Data Source and Connection String Problem headly Excel Programming 0 January 23rd 08 12:36 AM
oledb connection string problem in vb.net Manoj Nair Excel Programming 0 April 15th 06 08:41 AM
What is the connection string ? Jan Karel Pieterse Excel Programming 0 July 25th 03 11:37 AM


All times are GMT +1. The time now is 07:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"