Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default use ADO invoking dbf file in excel

how to use ADO invoking dbf file in excel,thus ,I hope to know more about ADO
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default use ADO invoking dbf file in excel

Hi,

Here is some sample code for an access DB
If you use f1 on some word like recorset you should get explanation from the
help file.

Sub showAdo()
'you have too make a reference via tools: Micrsoft ActiveX data Object 2.1

Dim cnObject As ADODB.Connection
Dim rec1 As ADODB.Recordset
Dim x As Integer, temp As String
Dim strPath As String
strPath = ThisWorkbook.Path

Set cnObject = New ADODB.Connection
Set rsObject1 = New ADODB.Recordset

cnObject.Open "Provider= Microsoft.Jet.OLEDB.4.0;" & "Data Source = " &
strPath & "\YourdataBase.mdb;"
rec1.Open "Select * from Your_Table ;", cnObject, adOpenForwardOnly,
adLockOptimistic

Do While rsObject1.EOF = False
For x = 4 To rec1.Fields.Count - 1
Debug.Print rec1.Fields(x).Name
If InStr(rec1.Fields(x).Value, vbLf) < 0 Then
Debug.Assert rec2.Fields(x).Value
End If
Next
rec1.MoveNext
Loop

rsObject1.Close
cnObject.Close
End Sub

Regards,
Jean-Yves


"hedia.ccf" wrote in message
...
how to use ADO invoking dbf file in excel,thus ,I hope to know more about

ADO


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 253
Default use ADO invoking dbf file in excel

Hi again

Found this example from Microsoft :
Regards,

JY

'NOTE: You must reference the appropriate application library before running
'the code examples. Click References on the Tools Menu, and select the
'appropriate object libraries. Also see Help for more information.

Sub RetrieveISAMdata()
''' NOTE: This subroutine requires that you reference the
''' latest version of the following library:
'''
''' Microsoft ActiveX Data Objects Library

Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim NewBook As Workbook
Dim PathToDatabase As String
Dim i As Integer

' Create the Connection object.
Set conn = New ADODB.Connection

' Set Database path string
PathToDatabase = Application.Path & "\" & _
Application.LanguageSettings.LanguageID(msoLanguag eIDInstall)

With conn
'Assign the connection string to the connection object.
.ConnectionString = "DRIVER={Microsoft dBase Driver (*.dbf)};" & _
"DBQ=" & PathToDatabase & ";" & _
"DefaultDir=" & PathToDatabase & "\"
' Open the connection.
.Open strConn
End With

' Create a new Recordset Object.
Set rst = New ADODB.Recordset

With rst
' Connect this recordset to the previously opened connection.
.ActiveConnection = conn
' Retrieve all records from the Customer table.
.Open "SELECT * FROM customer"
End With

' Add a new worksheet to this workbook
Set NewBook = Workbooks.Add
' Loop through all of the fields, returning the field names to the
worksheet.
For i = 0 To rst.Fields.Count - 1
NewBook.Sheets(1).Range("a1").Offset(0, i).Value =
rst.Fields(i).Name
Next i
' Copy the recordset to the new worksheet.
NewBook.Sheets(1).Range("a2").CopyFromRecordset rst

' Close the recordset.
Set rst = Nothing
' Close the Connection.
conn.Close
End Sub


"Jean-Yves" wrote in message
...
Hi,

Here is some sample code for an access DB
If you use f1 on some word like recorset you should get explanation from

the
help file.

Sub showAdo()
'you have too make a reference via tools: Micrsoft ActiveX data Object

2.1

Dim cnObject As ADODB.Connection
Dim rec1 As ADODB.Recordset
Dim x As Integer, temp As String
Dim strPath As String
strPath = ThisWorkbook.Path

Set cnObject = New ADODB.Connection
Set rsObject1 = New ADODB.Recordset

cnObject.Open "Provider= Microsoft.Jet.OLEDB.4.0;" & "Data Source = " &
strPath & "\YourdataBase.mdb;"
rec1.Open "Select * from Your_Table ;", cnObject, adOpenForwardOnly,
adLockOptimistic

Do While rsObject1.EOF = False
For x = 4 To rec1.Fields.Count - 1
Debug.Print rec1.Fields(x).Name
If InStr(rec1.Fields(x).Value, vbLf) < 0 Then
Debug.Assert rec2.Fields(x).Value
End If
Next
rec1.MoveNext
Loop

rsObject1.Close
cnObject.Close
End Sub

Regards,
Jean-Yves


"hedia.ccf" wrote in message
...
how to use ADO invoking dbf file in excel,thus ,I hope to know more

about
ADO




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
from browser opening csv in Excel and invoking template, how? Axe Victim Excel Discussion (Misc queries) 1 December 19th 06 10:49 PM
Problem with invoking project specific Sub in Excel???? Jim Cheng Excel Programming 0 November 19th 03 08:03 PM
Invoking Mail Merge from Excel John Topley Excel Programming 1 October 31st 03 08:09 PM
Excel Macro Code invoking InputBox. Andrew Thorne Excel Programming 0 July 30th 03 10:23 PM


All times are GMT +1. The time now is 12:42 AM.

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"