Log in

View Full Version : Error 13 when attaching a table



sportsguy
06-04-2013, 08:58 AM
Not sure why this attach table code doesn't work anymore. . .:banghead:
and gives an error, its been working for years, just put it in a new 2007 database.

dbtype = "Microsoft Access"
Error is - 13 - Type mismatch
Using 2.8 Library



Public Sub AttachTable(ByVal pstrDatabasePath, ByVal tblname, Optional ByVal tblNewname)
On Error GoTo Attach_Err
If IsNull(tblNewname) Then tblNewname = tblname
Debug.Print "tblNewname = " & tblNewname
Debug.Print "Database path = " & pstrDatabasePath
With DoCmd
.DeleteObject acTable, tblNewname
.TransferDatabase acLink, dbType, pstrDatabasePath, acTable, tblname, tblNewname
End With

Exit_Sub:
Exit Sub
Attach_Err:

If Err.Number = 7874 Then
Debug.Print Err.Number & " " & Err.Description & " when deleting table from local database - Macro continues"
Resume Next
ElseIf Err.Number = 3011 Then
Debug.Print Err.Number & " " & Err.Description & " when attaching table from an access database"
MsgBox "Wrong Access database! Please select the correct Access database!", vbCritical, "Financial Planning and Analysis"
Else
Debug.Print Err.Number & " " & Err.Description
MsgBox Err.Number & " " & Err.Description & " " & tblname, vbCritical, "Financial Planning and Analysis"
End If

End Sub

mrojas
09-10-2013, 05:55 PM
I would specify the parameters type, ByVal pstrDatabasePath as String...
This way there's no questions as to what type of parameter is expected.