Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I Use VBA to import DBF files??

Status
Not open for further replies.

emumaster

Programmer
Aug 30, 2001
31
US
I know I can import DBF's by hand, but I have a reason for wanting to use VBA to code this. Any suggestions on how to code this?
 
Here is the code you need to link to the DBF file.

Option Compare Database
Option Explicit


Function ConnectSource()
Dim db As Database
Dim myDataPath As String
Dim myDBF As String
Dim myNewDBF As String

Set db = CurrentDb
' get the path to the DBF file - here I just typed it in
myDataPath = "C:\Access 2000\Projects\Test"
' here is the name of the DBF file
myDBF = "ACCESS.DBF"
' the new name it will use to id the file - may be the same as myDBF
myNewDBF = "MyDBFfile"

On Error GoTo oops_err


ConnectOutput db, _
myNewDBF, _
"dBase III;DATABASE=" & myDataPath, myDBF

Exit Function
oops_err:
If Err.Number = 3265 Then Resume Next
MsgBox Err.Description, vbCritical
End Function
Function ConnectOutput(dbsTemp As Database, _
strTable As String, strConnect As String, _
strSourceTable As String)

Dim tdfLinked As TableDef
Dim rstLinked As Recordset
Dim intTemp As Integer

' Create a new TableDef, set its Connect and
' SourceTableName properties based on the passed
' arguments, and append it to the TableDefs collection.
Set tdfLinked = dbsTemp.CreateTableDef(strTable)

tdfLinked.Connect = strConnect
tdfLinked.SourceTableName = strSourceTable
dbsTemp.TableDefs.Append tdfLinked

Set rstLinked = dbsTemp.OpenRecordset(strTable)

End Function
 
I appreciate the code, but I wanted to IMPORT not LINK!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top