Forum Discussion

ITCEIAV's avatar
ITCEIAV
Copper Contributor
Jul 12, 2022

Split database, password-protected BE, creates err 3011 when using DoCmd.TransferDatabase

I have a front end (FE) and a back end (BE) split Access DB. The BE DB is password protected. I want to programmatically create a table in the BE, but also need to link the FE to it. I am able to cre...
  • arnel_gp's avatar
    Jul 13, 2022

    ITCEIAV 

    you can create this Sub to create the Linked table.

    after you create the New table in the BE, call it:

     

    Call RelinkTable("BE path + name", "theTableToLink", "NewLinkNameToCreate", "passwordOfdbhere")

     

    ' arnelgp
    Public Sub RelinkTable(ByVal DbPath As String, ByVal TableName As String, Optional ByVal LinkName As String, Optional ByVal dbPassword As String = "")
    '
    ' dbPath        = fullpath of the database (BE) to link
    ' TableName     = name of table to Link
    ' LinkName      = the new link tablename to create. if not supplied, TableName will be used.
    ' dbPassword    = the password for the BE (if password protected).
    '
        Dim db As dao.Database
        Dim td As dao.TableDef
        
        If Len(LinkName) < 1 Then
            LinkName = TableName
        End If
        
        Set db = CurrentDb
        Set td = Nothing
        If DCount("1", "MsysObjects", "Name = '" & LinkName & "' And Type = 6") > 0 Then
            db.TableDefs.Delete LinkName
        End If
        Set td = db.CreateTableDef(LinkName)
        td.SourceTableName = TableName
        td.Connect = "MS Access;PWD=" & dbPassword & ";DATABASE=" & DbPath
        db.TableDefs.Append td
        
        db.TableDefs.Refresh
        Application.RefreshDatabaseWindow
        Set td = Nothing
        Set db = Nothing
    End Sub

     

     

     

     

Resources