Search This Blog

Saturday, November 27, 2010

Importing dbf file to Access in vb

Few years back I have to create a script that will import dbf files to access. Of course we can always do this using import options in access. But as it happens I'm tired of doing it manually so I decided to write a script for this routine. What we need to do is just to invoke the docmd.transferDatabase as seen in the created fuction below.

Dim MyTable As TableDef
Dim MyDatabase As Database
Dim strLastUpdate, strDateCreated As Date
Dim Myrs  As Recordset
Dim intcount As Integer

'Function to Import database in dbf format
Public Function ImportDatabases(ByVal strDatabaseNametoImport As String, _
                                ByVal strDatabaseSource As String, _
                                ByVal strDatabaseType As String, _
                                ByVal strNameofTable As String)
    Dim BlExist As Boolean
    BlExist = fn_IsexistTable(Trim(strNameofTable))
        If BlExist = True Then
            If MsgBox(" Warning!! Table " & strNameofTable & " Already Existing. Last Update was " & strLastUpdate & " Overwrite?", vbQuestion + vbYesNo, "Downtime System") = vbYes Then
                fn_DeleteTable Trim(strNameofTable)
                DoCmd.TransferDatabase acImport, strDatabaseType, strDatabaseSource, acTable, strDatabaseNametoImport, strNameofTable, False
                   MsgBox "Finished Importing Table " & Trim(strNameofTable)
            Else
                Exit Function
            End If
        Else
                DoCmd.TransferDatabase acImport, strDatabaseType, strDatabaseSource, acTable, strDatabaseNametoImport, strNameofTable, False
                MsgBox "Finished Importing Table " & Trim(strNameofTable)
        End If
End Function

No comments:

Post a Comment