[AccessD] Create and Link Table in external database

Rocky Smolin rockysmolin at bchacc.com
Tue Jun 7 16:02:10 CDT 2016

Dear List:
I am trying to create and link to a new table in an external database.  The
create part works fine but the linking part fails on the last line:
dbFrontEnd.TableDefs.Append tdfLinked, with an Error 3001 Invalid argument,
but I can't see why.  
I tried changing  Dim tdfLinked As TableDef to Dim tdfLinked As DAO.TableDef
but same result.  Here's the code:
Dim db As DAO.Database
Dim dbFrontEnd As DAO.Database
Dim wrk As DAO.Workspace
Dim tdf As DAO.TableDef
Dim tdfLinked As TableDef

' Create Table
    Set tdf = db.CreateTableDef("tblPODetailRemarks")
    Set fld = tdf.CreateField("fldPODetailRemarksID", dbLong)
    fld.Attributes = dbAutoIncrField
    tdf.Fields.Append fld
    Set ind = tdf.CreateIndex("PrimaryKey")
    With ind
        .Fields.Append .CreateField("fldPODetailRemarksID")
        .Unique = False
        .Primary = True
    End With
    tdf.Indexes.Append ind
    Set fld = tdf.CreateField("fldPODetailRemarks", dbText, 255)
    tdf.Fields.Append fld
    db.TableDefs.Append tdf

' Link Table    
    Set dbFrontEnd = CurrentDb
    Set tdfLinked = dbFrontEnd.CreateTableDef("tblPODetailRemarks")
    tdfLinked.Connect = ";Database = " & gstrDatabaseName
    tdfLinked.SourceTableName = "tblPODetailRemarks"
    dbFrontEnd.TableDefs.Append tdfLinked
Does anyone see what I'm doing wrong?
Rocky Smolin
Beach Access Software
www.bchacc.com <http://www.bchacc.com/> 
www.e-z-mrp.com <http://www.e-z-mrp.com/> 
Skype: rocky.smolin

More information about the AccessD mailing list