当前位置: 动力学知识库 > 问答 > 编程问答 >

ms access - DoCmd.TransferDatabase gives a Type Mismatch error importing dBase IV tables

问题描述:

Code I found and modified:

Option Compare Database

Option Explicit

Sub DoImport()

Dim strPathFile As String, strFile As String, strPath As String

Dim strTable As String

Dim blnHasFieldNames As Boolean

blnHasFieldNames = True

strPath = "C:\mypath\"

strFile = Dir(strPath & "*.dbf")

Do While Len(strFile) > 0

strPathFile = strPath & strFile

strTable = Left(strFile, Len(strFile) - 4)

DoCmd.TransferDatabase acImport, "dBase IV", _

strTable, strPathFile, blnHasFieldNames

strFile = Dir()

Loop

End Sub

It gives a Type Mismatch error every time on the DoCmd.TransferDatabase command. I have added a Watch, and made sure that all the variables are correct. I can't see what's going on to make this fail.

I'm trying to import about 20+ dBase IV files at once. I am executing using Control-G and then running. Access 2007.

网友答案:

You are missing the ObjectType parameter in your TransferDatabase call.

DoCmd.TransferDatabase acImport, "dBase IV", _
    strTable, acTable, strPathFile, ...
              ^^^^^^^

In addition, TransferDatabase has no parameter hasFieldNames. See DoCmd.TransferDatabase Method (Access) for the syntax:

DoCmd.TransferDatabase _
    TransferType, _
    DatabaseType, _
    DatabaseName, _
    ObjectType, _
    Source, _
    Destination, _
    StructureOnly, _
    StoreLogin)
分享给朋友:
您可能感兴趣的文章:
随机阅读: