LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default connect to Access 2007

In 2005, thanks to code posted on this board, I created a workbook
which connects to Access & retrieves data from recordsets. The code
works fine, except now when I try to use it with Access 2007 I get the
error:
"Unrecognized database format 'C:\...\myfile.accdb'

Is there a way to update the code so it will work with Access 2007?
Thanks in advance for any help! Here is the relevant section:

Public cnMinistry As ADODB.Connection
Private Function ConnectToDatabase() As Boolean
'instantiate the connection & connect
Set cnMinistry = New Connection
cnMinistry.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" & strFileToOpen & ";"
cnMinistry.Open '<--- error happens here
If cnMinistry.State = adStateOpen Then ConnectToDatabase = True
End Function

References:
Visual Basic for Applications
Microsoft Excel 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Object Library
Microsoft Forms 2.0 Object Library
Microsoft.ActiveX Data Objects 2.5 Library

Some more code that may have to change:

Private Sub ImportAccessTable(cn As ADODB.Connection, TableName As
String, TargetRange As Range)
Dim rs As ADODB.Recordset, intColIndex As Integer
Set TargetRange = TargetRange.Cells(1, 1)
Set rs = New ADODB.Recordset
rs.Open TableName, cn, adOpenStatic, adLockOptimistic, adCmdTable
For intColIndex = 0 To rs.Fields.Count - 1 ' the field names
TargetRange.Offset(0, intColIndex).Value =
rs.Fields(intColIndex).Name
Next
TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset data
rs.Close
Set rs = Nothing
End Sub

 
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
How do I connect to access 2007 data from excel? Marilyn Myers Excel Discussion (Misc queries) 3 December 12th 08 04:15 PM
Excel VAB+ADO connect ACCESS with SQL alexsas Excel Programming 2 August 21st 07 02:24 PM
Connect to MS Access with Password via VBA matelot Excel Programming 2 September 19th 06 03:55 PM
Help with using ADO to connect Excel to Access [email protected] Excel Programming 4 June 29th 06 10:26 AM
ADO Connect Access gti_jobert[_78_] Excel Programming 5 April 4th 06 01:24 PM


All times are GMT +1. The time now is 04:26 AM.

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

About Us

"It's about Microsoft Excel"