VBA ADODB import dBASE file more then 8 characters long

mattey28

New Member
Joined
Aug 10, 2007
Messages
18
Hi I'm trying to import dBase file to Excel. My code looks like this:
Code:
Sub MFACTImport(TargetRange As Range)

DBFullName = "C:\temp\MISS_TRXCUR.DBF"
DBDirectory = "C:\temp"
TableName = "MISS_TRXCUR"

Dim cn As ADODB.Connection, rs As ADODB.Recordset, intColIndex As Integer
    Set TargetRange = TargetRange.Cells(1, 1)
    
    Set cn = New ADODB.Connection
    cn.Open "Driver={Microsoft dBASE Driver (*.dbf)};DriverID=277;ReadOnly=True;Dbq=" & DBDirectory & ";"
    Set rs = New ADODB.Recordset
    With rs

        .Open TableName, cn, adOpenStatic, adLockOptimistic, adCmdTable
        
        For intColIndex = 0 To rs.Fields.Count - 1 ' NAZWY PÓL
            TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex).Name
        Next
        TargetRange.Offset(1, 0).CopyFromRecordset rs ' REKORDY

    End With
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
End Sub

The problem is that this macro imports file with name MISS_TRX.DBF not MISS_TRXCUR.DBF. Is there a way to process file with name longer then 8.3 characters ?
Thanks for any help :)
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Thanks to code you pointed I have DOS version of directory and file name but is the table name also coded in 8 characters ?

I change my code and I get different errors, but is ussualy stops at cn.Open line.
Should I use full path with file name (DOS encoded) in Dbq= ?
 
Upvote 0
Thanks for help Andrew!

I've altered my code to
Code:
Set cn = New ADODB.Connection
  cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Data Source=" & DBDirectory & _
  ";Extended Properties=DBASE IV;"
  Set rs = New ADODB.Recordset
    With rs
      .Open "SELECT * FROM [MISS_T~3.dbf]", cn, , , adCmdText

and it works!!
 
Upvote 0

Forum statistics

Threads
1,213,562
Messages
6,114,322
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top