Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Connected from Excel to Access

What other options are needed to be checked in the Microsoft Access
Object Library (Reference - VBA Project) in order to successfully
connect from Excel to Access using a Macro?

I currently have the following options checked:

Visual Basics for Applications
Microsoft Excel 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Oject Library
Microsoft ADO Ext. 2.8 for DDL and Security
MIcrosoft Access 11.0 Object Library

I appreciate your assistance.

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Connected from Excel to Access

Depends houw you are trying to connect... ADO, DAO, ???. For ADO you need.

Microsoft ActiveX Data Objects 2.? Library.

One thing to note is that you may want to select a library somewhere around
2.5 in order to ensure backwards compatability with older version of XL.
--
HTH...

Jim Thomlinson


"Damil4real" wrote:

What other options are needed to be checked in the Microsoft Access
Object Library (Reference - VBA Project) in order to successfully
connect from Excel to Access using a Macro?

I currently have the following options checked:

Visual Basics for Applications
Microsoft Excel 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Oject Library
Microsoft ADO Ext. 2.8 for DDL and Security
MIcrosoft Access 11.0 Object Library

I appreciate your assistance.

Thanks!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 34
Default Connected from Excel to Access

On Sep 15, 10:33*am, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Depends houw you are trying to connect... ADO, DAO, ???. For ADO you need..

Microsoft ActiveX Data Objects 2.? Library.

One thing to note is that you may want to select a library somewhere around
2.5 in order to ensure backwards compatability with older version of XL.
--
HTH...

Jim Thomlinson



"Damil4real" wrote:
What other options are needed to be checked in the Microsoft Access
Object Library (Reference - VBA Project) in order to successfully
connect from Excel to Access using a Macro?


I currently have the following options checked:


Visual Basics for Applications
Microsoft Excel 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Oject Library
Microsoft *ADO Ext. 2.8 for DDL and Security
MIcrosoft Access 11.0 Object Library


I appreciate your assistance.


Thanks!- Hide quoted text -


- Show quoted text -


Thanks for the response, Jim

I'm still kinda new to all of these so I don't really know the
difference btw ADO or DAO.

The code is below. What kind of connection is it? Thanks a bunch!

Public Sub GetUniqueDataFromAccessFields(MyDatabaseFilePathAn dName As
String, MyTable As String, _
MyTableField1 As String, _
MyTableField2 As String, _
MyTableField3 As String, _
MyTableField4 As String, _
MyTableField5 As String, _
MyTableField6 As String, _
MyTableField7 As String, _
DestSheetRange As Range,
ClearRange As Boolean)

Dim MyConnection As String
Dim MySQL As String
Dim MyDatabase As Object
Dim I As Integer
Dim str1 As Variant


'If ClearRange = True clear all cells in column K:O
If ClearRange Then
Sheets(DestSheetRange.Parent.Name).Range(DestSheet Range.Address,
DestSheetRange.Offset(0, 4)).EntireColumn.ClearContents

'Create connection string
MyConnection = "Provider=Microsoft.Jet.OLEDB.4.0;"
MyConnection = MyConnection & "Data Source=" &
MyDatabaseFilePathAndName & ";"

' Create MySQL string
str1 = Array(MyTableField1, MyTableField2, MyTableField3,
MyTableField4, MyTableField5, MyTableField6, MyTableField7)

MySQL = ""
For I = LBound(str1) To UBound(str1)
If str1(I) < "" Then
MySQL = "Select Distinct [" & str1(I) & "] From " &
MyTable

' Open the database and copy the data
On Error GoTo SomethingWrong
Set MyDatabase = CreateObject("adodb.recordset")
MyDatabase.Open MySQL, MyConnection, 0, 1, 1

' Check to make sure we received data and copy the data
If Not MyDatabase.EOF Then
'Copy to K:M in the Criteria sheet (Columns are
hidden)
DestSheetRange.Offset(0, I).CopyFromRecordset
MyDatabase
Else
MsgBox "No records returned from : " & str1(I),
vbCritical
End If

MyDatabase.Close
Set MyDatabase = Nothing
End If
Next I

Exit Sub

SomethingWrong:
On Error GoTo 0
Set MyDatabase = Nothing
MsgBox "Error copying unique data", vbCritical, "Test Access data
to Excel"

End Sub
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Connected from Excel to Access

You are using ADO. Note the line
Set MyDatabase = CreateObject("adodb.recordset")

That being said you are using something called late binding where your
references are created at run time and not at design time. To that end you do
not need to add any references. I copied your code into a blank workbook and
it compiled just fine. What makes you think you need to add a reference?
--
HTH...

Jim Thomlinson


"Damil4real" wrote:

On Sep 15, 10:33 am, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
Depends houw you are trying to connect... ADO, DAO, ???. For ADO you need..

Microsoft ActiveX Data Objects 2.? Library.

One thing to note is that you may want to select a library somewhere around
2.5 in order to ensure backwards compatability with older version of XL.
--
HTH...

Jim Thomlinson



"Damil4real" wrote:
What other options are needed to be checked in the Microsoft Access
Object Library (Reference - VBA Project) in order to successfully
connect from Excel to Access using a Macro?


I currently have the following options checked:


Visual Basics for Applications
Microsoft Excel 11.0 Object Library
OLE Automation
Microsoft Office 11.0 Oject Library
Microsoft ADO Ext. 2.8 for DDL and Security
MIcrosoft Access 11.0 Object Library


I appreciate your assistance.


Thanks!- Hide quoted text -


- Show quoted text -


Thanks for the response, Jim

I'm still kinda new to all of these so I don't really know the
difference btw ADO or DAO.

The code is below. What kind of connection is it? Thanks a bunch!

Public Sub GetUniqueDataFromAccessFields(MyDatabaseFilePathAn dName As
String, MyTable As String, _
MyTableField1 As String, _
MyTableField2 As String, _
MyTableField3 As String, _
MyTableField4 As String, _
MyTableField5 As String, _
MyTableField6 As String, _
MyTableField7 As String, _
DestSheetRange As Range,
ClearRange As Boolean)

Dim MyConnection As String
Dim MySQL As String
Dim MyDatabase As Object
Dim I As Integer
Dim str1 As Variant


'If ClearRange = True clear all cells in column K:O
If ClearRange Then
Sheets(DestSheetRange.Parent.Name).Range(DestSheet Range.Address,
DestSheetRange.Offset(0, 4)).EntireColumn.ClearContents

'Create connection string
MyConnection = "Provider=Microsoft.Jet.OLEDB.4.0;"
MyConnection = MyConnection & "Data Source=" &
MyDatabaseFilePathAndName & ";"

' Create MySQL string
str1 = Array(MyTableField1, MyTableField2, MyTableField3,
MyTableField4, MyTableField5, MyTableField6, MyTableField7)

MySQL = ""
For I = LBound(str1) To UBound(str1)
If str1(I) < "" Then
MySQL = "Select Distinct [" & str1(I) & "] From " &
MyTable

' Open the database and copy the data
On Error GoTo SomethingWrong
Set MyDatabase = CreateObject("adodb.recordset")
MyDatabase.Open MySQL, MyConnection, 0, 1, 1

' Check to make sure we received data and copy the data
If Not MyDatabase.EOF Then
'Copy to K:M in the Criteria sheet (Columns are
hidden)
DestSheetRange.Offset(0, I).CopyFromRecordset
MyDatabase
Else
MsgBox "No records returned from : " & str1(I),
vbCritical
End If

MyDatabase.Close
Set MyDatabase = Nothing
End If
Next I

Exit Sub

SomethingWrong:
On Error GoTo 0
Set MyDatabase = Nothing
MsgBox "Error copying unique data", vbCritical, "Test Access data
to Excel"

End Sub

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
Excel Pivot Table connected to an Access Database Data Source Alex Zimmerhaven Excel Discussion (Misc queries) 2 June 10th 08 03:04 AM
Excel slow but NOT when connected remotely!! T-Bone Excel Discussion (Misc queries) 1 September 21st 06 02:55 PM
How do I have excel setup so formulas is connected between sheets davenportgirl Excel Worksheet Functions 7 September 7th 06 09:45 PM
Excel runs slowly, but only when connected to a network Pete Excel Discussion (Misc queries) 3 November 28th 05 08:25 PM
HOW TO HIGHLIGHT DATA CONNECTED TO A HYPERLINK IN EXCEL toni Excel Discussion (Misc queries) 0 July 21st 05 11:06 AM


All times are GMT +1. The time now is 11:30 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"