Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
I need to access dbf files from AutoCad using vba. Here is my code that doesn't work
'http://www.myengineeringworld.net/2013/09/read-dbf-files-using-vba.html Dim con As Object Dim rs As Object Dim sql As String Dim i As Integer Dim j As Integer CommonDialog1.DialogTitle = "Open .dbf data base file." CommonDialog1.ShowOpen ft$ = CommonDialog1.FileTitle: 'ft$ is = to filename.dbf fn$ = CommonDialog1.FileName fnn$ = fn$ c% = InStr(1, fn$, ft$) fn$ = Left(fn$, c% - 2): 'fn$ is = to the path to filename.dbf without the 'final \ character 'Create the ADODB connection object. Set con = CreateObject("ADODB.connection") 'Open the connection. con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & fn$ & ";Extended Properties=dBASE IV;" 'Create the SQL statement to read the file. 'Note that the filename is used instead of the table name. sql = "SELECT * FROM " & ft$ & ";" 'Create the ADODB recordset object. Set rs = CreateObject("ADODB.recordset") 'Open the recordset. rs.Open sql, con
The last statement creates an error saying that the database engine could not find the object filename.dbf. I tried leaving the trailing \ character on the path name string, but I get the same error. Does uppercase/lowercase text have any influence? Some of the file names and path names have lowercase letters.
Thank you
John
Solved! Go to Solution.