Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
from browser opening csv in Excel and invoking template, how? | Excel Discussion (Misc queries) | |||
Problem with invoking project specific Sub in Excel???? | Excel Programming | |||
Invoking Mail Merge from Excel | Excel Programming | |||
Excel Macro Code invoking InputBox. | Excel Programming |