Access 2013 - Dbase (.dbf) Table Import option

Anonymous
2013-02-03T16:16:55+00:00

I need to be able to import read/write Dbase dbf tables - yes they are still around so why has the standard option that was in Access 2010 gone?

I have seen mention of ISAM, which is gobbledegook to me. So please a simple answer - what do I need to install or change and how do I do it?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
ScottGem 68,840 Reputation points Volunteer Moderator
2016-09-08T09:08:22+00:00

Was this answer helpful?

60+ people found this answer helpful.
0 comments No comments

158 additional answers

Sort by: Newest
  1. Anonymous
    2015-02-04T05:21:17+00:00

    it only supports basic types TEXT,MEMO,DATETIME,DOUBLE,YESNO data types.

    You can also improve the code to only parameter the directory path then all the dbf files on that directory will be imported to tables on your local access database. would give us ease.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-02-04T05:18:26+00:00

    Ok.

    1. In your access database, add a new Module (under Database  Tools tab in ribbon)
    2. Paste this code then save.

    'BEGIN                                                                                                                         

    Function ImportDBF(ByVal dbfFileDir As String, _

                        ByVal dbfTableName As String)

        dbfFileDir = dbfFileDir & "\"

        Dim dbfCn As Object

        Dim dbfRs As Object

        Dim dbfStrSql As String

        Dim dbfStrConnection As String

        Set dbfCn = CreateObject("ADODB.Connection")

        dbfStrConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

            "Data Source=" & dbfFileDir & ";" & _

            "Extended Properties=dBase IV"

        dbfStrSql = "SELECT * FROM " & dbfTableName & ""

        dbfCn.Open dbfStrConnection

        Set dbfRs = dbfCn.Execute(dbfStrSql)

        Dim fieldIndex As Integer

        Dim ddlNewAccessTable As String

        Dim ddlColumns As String

        Dim dmlInsert As String

        Dim dmlColumns As String

        Dim dmlValues As String

        dmlColumns = "("

        ddlColumns = "("

        For fieldIndex = 0 To dbfRs.Fields.Count - 1

            dmlColumns = dmlColumns & dbfRs.Fields(fieldIndex).Name & ","

            Select Case dbfRs.Fields(fieldIndex).Type

                Case 202

                   ddlColumns = ddlColumns & dbfRs.Fields(fieldIndex).Name & " " & _

                                "TEXT,"

                Case 203

                    ddlColumns = ddlColumns & dbfRs.Fields(fieldIndex).Name & " " & _

                                "MEMO,"

                Case 5

                    ddlColumns = ddlColumns & dbfRs.Fields(fieldIndex).Name & " " & _

                                "DOUBLE,"

                Case 7

                    ddlColumns = ddlColumns & dbfRs.Fields(fieldIndex).Name & " " & _

                                "DATETIME,"

                Case 11

                    ddlColumns = ddlColumns & dbfRs.Fields(fieldIndex).Name & " " & _

                                "YESNO,"

                Case Else

                    ddlColumns = ddlColumns & dbfRs.Fields(fieldIndex).Name & " " & _

                                "TEXT,"

            End Select

        Next fieldIndex

        dmlColumns = Left(dmlColumns, Len(dmlColumns) - 1) & ")"

        ddlColumns = Left(ddlColumns, Len(ddlColumns) - 1) & ")"

        ddlNewAccessTable = "CREATE TABLE " & dbfTableName & " " & ddlColumns & ";"

        Dim myDb As Database

        Set myDb = CurrentDb()

        myDb.Execute ddlNewAccessTable

        Dim fieldIndex2 As Integer

        While Not dbfRs.EOF

        dmlInsert = ""

        dmlValues = "("

            For fieldIndex2 = 0 To dbfRs.Fields.Count - 1

                Select Case dbfRs(fieldIndex2).Type

                    Case 202

                         dmlValues = dmlValues & "'" & dbfRs(fieldIndex2).Value & "',"

                    Case 203

                        dmlValues = dmlValues & "'" & dbfRs(fieldIndex2).Value & "',"

                    Case 5

                        dmlValues = dmlValues & dbfRs(fieldIndex2).Value & ","

                    Case 11

                        dmlValues = dmlValues & dbfRs(fieldIndex2).Value & ","

                    Case 7

                        If IsDate(dbfRs(fieldIndex2).Value) Then

                            dmlValues = dmlValues & "#" & dbfRs(fieldIndex2).Value & "#,"

                        Else

                            dmlValues = dmlValues & "NULL,"

                        End If

                    Case Else

                        dmlValues = dmlValues & "'" & dbfRs(fieldIndex2).Value & "',"

                    End Select

            Next fieldIndex2

            dmlValues = Left(dmlValues, Len(dmlValues) - 1) & ")"

            dmlInsert = "INSERT INTO " & dbfTableName & dmlColumns & " VALUES" & dmlValues

            myDb.Execute dmlInsert

            dbfRs.MoveNext

        Wend

        MsgBox "Finished! " & Now

    End Function

    'END

    1. Create a form and add a button (use an event to call this function). Here is a sample:

    'You call it like this:

    Private Sub Command0_Click()

        ImportDBF "C:\CustomDBFTablesDirectory", "DB_TABLENAME"

    End Sub

    'It will create a new local access table with name same as your inputted dbftablename

    'You can run this without referencing ADO Library

    1. A new local table will be added to your access file.

    This should work on you.

    Anyone can improve this code and share it with us... then the world could be a better place :) hahahah

    Was this answer helpful?

    0 comments No comments
  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. Anonymous
    2015-02-04T03:03:55+00:00

    Thanks. How can we connect that?

    Can you please write a step-by-step guide to get it working?

    Was this answer helpful?

    0 comments No comments