hyperlink

L

Lillian

How do you delete a hyperlink in a current opened database and create a new
link to another table in another database using VBA?

TableName linked to DatabaseName.mdb which is "C:\Folder\DatabaseName.mdb"

Change to:

TableName linked to DatabaseName.mdb which is "D:\Folder\DatabaseName.mdb"
 
A

Allen Browne

Set the Connect property of the TableDef.

Don't forget to RefreshLink as well.
 
L

Lillian

Allen said:
Set the Connect property of the TableDef.

Don't forget to RefreshLink as well.


Ok. This works.
The only question I have now is this works with a current opened database
and links into it. How do you link from another database to another
database?

The Set dbsTemp = CurrentDb must be what needs to be changed to the path to
the other database.

I tried Set dbsTemp = "C:\folder\MyDatabase.mdb"
But it didn't work. Can it be done?


Dim dbsTemp As Database
Dim strMenu As String
Dim strInput As String

' Open a Microsoft Jet database to which you will link
' a table.
Set dbsTemp = CurrentDb

' Call the ConnectOutput procedure. The third argument
' will be used as the Connect string, and the fourth
' argument will be used as the SourceTableName.
ConnectOutput dbsTemp, _
"LinkedTable", _
";DATABASE=C:\db1.mdb", _
"Dates"

End Sub

Sub ConnectOutput(dbsTemp As Database, _
strTable As String, strConnect As String, _
strSourceTable As String)

Dim tdfLinked As TableDef

' Create a new TableDef, set its Connect and
' SourceTableName properties based on the passed
' arguments, and append it to the TableDefs collection.
Set tdfLinked = dbsTemp.CreateTableDef(strTable)

tdfLinked.Connect = strConnect
tdfLinked.SourceTableName = strSourceTable
dbsTemp.TableDefs.Append tdfLinked

End Sub
 
A

Allen Browne

You can create a linked table with CreateTableDef

Theres an example in the middle of this page:
http://www.mvps.org/access/tables/tbl0010.htm
Search the page for CreateTableDef. It shows how to specify the linked table
name, the source table namd and the connect string, and then append the
linked table to the TableDefs collection.
 
L

Lillian

Allen said:
You can create a linked table with CreateTableDef

Theres an example in the middle of this page:
http://www.mvps.org/access/tables/tbl0010.htm
Search the page for CreateTableDef. It shows how to specify the linked
table name, the source table namd and the connect string, and then append
the linked table to the TableDefs collection.

My question is:
Is it possible to retrieve table information from an external Access db.
Then append chosen tables NOT TO the current access db by linking them but
to another external Access db?

I can with the current opened access db but I am having problem with linking
to the other db.


Link a table between two external access db.


It seams that the CreateTableDef only works with CurrentDb not someother
path.
 
L

Lillian

Allen said:
Use OpenDatabase() to get a reference to a file, e.g.
c:\MyFolder\MyFile.mdb

Then use CreateTableDef() to create the link in that database to another
file.


Ok. It is working.
One more issue.

How do I delete the old link in the opened database?
I need to delete it first or the new link will goto link1.
So I need to delete it.
 
A

Allen Browne

Use OpenDatabase() to get a reference to a file, e.g. c:\MyFolder\MyFile.mdb

Then use CreateTableDef() to create the link in that database to another
file.
 
L

Lillian

Allen said:
The page I suggested lasts shows you how to DeleteObject, or you can use
the Delete method of the TableDefs collection.


It is working completely. Thank you so much.
TableDefs is powerful.
 
A

Allen Browne

The page I suggested lasts shows you how to DeleteObject, or you can use the
Delete method of the TableDefs collection.
 
Top