S
Stacey Levine
My code is below. I am moving tables from Access to SQL. This code is run
(because many databases did link to a table residing in Access), from part
of a program that has determined what access databases are using my table.
Everything works correctly, except it is not saving the password with the
newly linked table. So when I go into access to check the table, I have to
enter the password .. to get to the data. Any ideas what is wrong? Thanks.
Stacey
Private Sub RelinkTable(WhatDB As String)
Dim MyDB As Database
Dim NewLink As String
Dim dbs As DAO.Database
Dim dbe As DAO.DBEngine
Dim tDef As DAO.TableDef
NewLink = "ODBC;DSN=MerchData;UID=MyUser;PWD=MyPassword;DATABASE=Merch"
Set dbe = New DAO.DBEngine
Me.lblStatus.Caption = "Change database " & WhatDB
Me.lblStatus.Refresh
Set dbs = dbe.OpenDatabase(WhatDB)
dbs.TableDefs.Delete (Me.txtTableName.Text)
Set tDef = dbs.CreateTableDef
tDef.Connect = NewLink
tDef.SourceTableName = Me.txtSqlName.Text
tDef.Name = txtSqlName.Text
dbs.TableDefs.Append tDef
dbs.Close
CloseandLeave:
Set tDef = Nothing
Set dbs = Nothing
Set dbe = Nothing
(because many databases did link to a table residing in Access), from part
of a program that has determined what access databases are using my table.
Everything works correctly, except it is not saving the password with the
newly linked table. So when I go into access to check the table, I have to
enter the password .. to get to the data. Any ideas what is wrong? Thanks.
Stacey
Private Sub RelinkTable(WhatDB As String)
Dim MyDB As Database
Dim NewLink As String
Dim dbs As DAO.Database
Dim dbe As DAO.DBEngine
Dim tDef As DAO.TableDef
NewLink = "ODBC;DSN=MerchData;UID=MyUser;PWD=MyPassword;DATABASE=Merch"
Set dbe = New DAO.DBEngine
Me.lblStatus.Caption = "Change database " & WhatDB
Me.lblStatus.Refresh
Set dbs = dbe.OpenDatabase(WhatDB)
dbs.TableDefs.Delete (Me.txtTableName.Text)
Set tDef = dbs.CreateTableDef
tDef.Connect = NewLink
tDef.SourceTableName = Me.txtSqlName.Text
tDef.Name = txtSqlName.Text
dbs.TableDefs.Append tDef
dbs.Close
CloseandLeave:
Set tDef = Nothing
Set dbs = Nothing
Set dbe = Nothing