Excel VBA & ADO - retreiving data from Approach dBase IV .dbf files

E

EddyT

Hi folks,
I'm trying to send persuade Excel to send queries (SQL) to an approac
dBase IV (.dbf) file.

I've got these connection methods (courtesy of one of the tips here
which allows me to connect to another .xls file in the same way, but m
attempts to modify it so that I can query the dbf have so far bee
unsuccessful. What's the equivalent code to achieve what I'm trying t
do?

Sub openCN(cn As ADODB.Connection)
' open connection and leave open
Set cn = New ADODB.Connection
cn.Open "DRIVER={Microsoft Excel Drive
(*.xls)};DriverId=790;ReadOnly=True;" & _
"DBQ=" & datafile & ";" ' DriverId=790: Excel 97/2000
End Sub

Sub openRS(strSQL As String, cn As ADODB.Connection, rs A
ADODB.Recordset)
'open recordset and leave cn,rs open

On Error GoTo errhand
Set rs = New ADODB.Recordset
rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
Exit Sub

'error handling
errhand:
MsgBox "Error in openRS." & vbCr & vbCr & _
"SQL:" & strSQL
End Su
 
B

Bob Phillips

You just need a different connection string

Sub openCN(cn As ADODB.Connection)
' open connection and leave open
Set cn = New ADODB.Connection
cn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & _
"DriverID=277;" & _
"Dbq=c:\somepath"

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top