linking tables

  • Thread starter Thread starter J. Adams
  • Start date Start date
J

J. Adams

Hi,

I am new to Access. I am trying to link two tables using
VBA, one template table (no records, but same strcuture)
in the front end user interface to the source table in
the back end database. I can't really figure out how to
do it. I went through the object browser and the only
code I could find there was "Access.acCmdLinkTables". I
couldn't find an example of how to use this code or if it
even applies to my case. My question: can I and if so how
do I use this code to link my tables. If this is not the
way to do it can someone point me in the right direction.

Thanks for your help.

J. Adams..
 
You don't link a table to another table in Access.

What happens when you use table linking is that you connect
a table from a target db into the one you're working in.
The table behaves as if it's in your database even though
it's in another file.
 
-----Original Message-----
You don't link a table to another table in Access.

What happens when you use table linking is that you connect
a table from a target db into the one you're working in.
The table behaves as if it's in your database even though
it's in another file.

Pardon my ignorance but isn't that what happens with a
split Access database? The tables in the backend are
linked to the front end. And if I am going about it the
wrong way, then what method should I be using i.e. VBA
code?

Thanks

JA..
 
J. Adams said:
Hi,

I am new to Access. I am trying to link two tables using
VBA, one template table (no records, but same strcuture)
in the front end user interface to the source table in
the back end database. I can't really figure out how to
do it. I went through the object browser and the only
code I could find there was "Access.acCmdLinkTables". I
couldn't find an example of how to use this code or if it
even applies to my case. My question: can I and if so how
do I use this code to link my tables. If this is not the
way to do it can someone point me in the right direction.

Thanks for your help.

J. Adams..

Hope this can help you

---------------------------------
Private Sub Command0_Click()
Dim db As Database, n As Integer, i As Integer
Dim TFileName As String, LinkedTable As TableDef
Dim LocalTableName() As String, TableArray() As String

Set db = CurrentDb

' External database
TFileName = "C:\JollyService_2004\JollyService_T.mdb"

DoCmd.Hourglass True
n = 4

ReDim TableArray(1 To n)
' Tables in external database
TableArray(1) = "t_UM"
TableArray(2) = "t_IVA_Aliq"
TableArray(3) = "t_Trasporti"
TableArray(4) = "t_CT"

ReDim LocalTableName(1 To n)
' Local names for linked tables
LocalTableName(1) = "T1"
LocalTableName(2) = "T2"
LocalTableName(3) = "T3"
LocalTableName(4) = "T4"

' If you want the local tables to have the same
' names as the external ones' replace
' LocalTableName(i) with TableArray(i)
For i = 1 To n
Set LinkedTable = db.CreateTableDef(LocalTableName(i))
'Set LinkedTable = db.CreateTableDef(TableArray(i))
LinkedTable.Connect = ";DATABASE=" & TFileName
LinkedTable.SourceTableName = TableArray(i)
db.TableDefs.Append LinkedTable
Next i
db.TableDefs.Refresh

DoCmd.Hourglass False

End Sub
 
Thanks for pointing out those websites for me. I know I
have a lot to learn about Access and it will surely
help. I come from a PowerBuilder-Sybase background so
this stuff is new to me, similar but new..

Regards,

J. Adams
 
Back
Top