by Trinh Nguyen (4 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 30th July 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Transfer data from .dbf file into .mdb Table
API Declarations
Public InRs As New ADODB.Recordset
Public OutCon As New ADODB.Connection
Public OutRs As New ADODB.Recordset
'Need to have an Employees.mdb (Access database with Employees table to start
'Need to have a te
Private Sub TransferDBF2MDB()
Dim StrPath As String
StrPath = "XXXXX.dbf" 'Your dbf File
'Point connection to database
InCon.Open "Driver={Microsoft dBASE Driver(*.dbf)};DriverID=277;Dbp=.\;"
OutCon.Open "Driver={Microsoft Access Driver(*.mdb)};Dbq=.\XXXSX.mdb;Uid=Admin;Pwd=;"
'Point Recordset to connection, note that "Temp" is the table name in XXXXX.mdb
InRs.Open "XXXXX.dbf", InCon, adOpenDynamic, adLockOptimistic, adCmdTable
OutRs.Open "Temp", OutCon, adOpenDynamic, adLockOptimistic, adCmdTable
'Read input database until EOF
Do Until InRs.EOF
OutRs.AddNew 'Insert a new record
'copy data from input record into output record
OutRs!Field0 = InRs.Fields(0)
OutRs!Field1 = InRs.Fields(1)
OutRs!Field2 = InRs.Fields(2) '...and so on
OutRs.Update
InRs.MoveNext
Loop
'Don't Forget to Close both files
Inrs.Close
InCon.Close
Set InCon = Nothing
Set InRs = Nothing
OutRs.Close
OutCon.Close
Set OutRs = Nothing
Set OutCon = Nothing
'Delete the dbf file
Kill StrPath 'Kill "XXXXX.dbf"
End Sub