Forum Discussion
ITCEIAV
Jul 12, 2022Copper Contributor
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...
- Jul 13, 2022
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
arnel_gp
Jul 13, 2022Iron Contributor
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
- ITCEIAVJul 13, 2022Copper Contributorarnel_gp, I implemented this and it worked. It failed at first, but I removed the brackets that I have been using for 16 years around table names and it worked. I will experiment and see if that makes a difference. Maybe there is an anomaly?! Thank you again, MS! 🤷:male_sign:
For some reason it says the DB is left in an unusual state. Will post the error here, but I have to get to an appointment in a few mins.
Thank you very much for this solution!