Urgent-Create Link in code

doulostheou

Registered User.
Local time
Yesterday, 22:05
Joined
Feb 8, 2002
Messages
314
This was brought up under different circumstances in a different post, and I hate to repost it because I don't want to be abusing the system. However, I need to be able to take care of this as soon as I come in tomorrow and the other post was dealing with a different issue.

Each of my users has their own database. I have lost a great deal of information from my Master DB, but that information is stored in a table on each individual's database named "Storage." Someone had informed me that you can create a link in code.

Each DB is named with the representative's first initial and last name. I already have a table that stores the first initial and last name of each employee. I am going to loop through the "MaintenanceList" table to obtain the only part of the file name that will change from the "LogsheetID". The file will look like this "T:/Logsheet/Employees/kbishop.mdb" with the kbishop changing per employee.

Using Access 97, how can I create a link to Storage for each LogsheetID in the loop, so I can use an append query to bring over all records after the specified date for each rep?

Thanks in advance for your help!!!

[This message has been edited by doulostheou (edited 04-26-2002).]
 
Check the online help for the CreateTableDef method. Click the Examples link and review the examples, particularly the last one, which deals with connecting a linked table.
 
I was looking at this last night, but I'm in over my head. I don't understand what I'm looking at. Where do I tell it which database to get the linked table from? I'm assuming its here:

tdfRoyalties.Connect = _
"ODBC;DATABASE=pubs;UID=sa;PWD=;DSN=Publishers"

But I don't understand where to enter the path for my database. Part of the problem may be that the example is dealing with a SQL Server database.
 
I guess I can make my problem more specific. I'm trying to test this in a sample database and am using the following code as pulled together from help files:

Dim dbs As Database, tdf As TableDef
' Return reference to current database.
Set dbs = CurrentDb
' Create new TableDef object.
Set tdf = dbs.CreateTableDef("Storage")
' Attach table
tdf.Connect = "T:\logsheets\Employees\kbishop.mdb"
tdf.SourceTableName = "Storage"
dbs.TableDefs.Append tdf
Set dbs = Nothing

The problem is with the line where I connect to the .mdb file. I get an error message that states it couldn't find installable ISAM. But the help file says that ISAM (whatever that is) shouldn't be needed with .mdb files.

The help file for the connect property states that I should not have to specify the databasetype as done in the example.

Where am I going wrong?
 
I think ISAM is refering to your connection string.
This is an error that can occure when using VB to connect to an Access database using DAO or ADO.
I've not come accross it in stand alone Access though.
I have a database that picks out DBF files from a folder and appends them to a table with a query.
If you think it might help I can post the method & code that I used.
 
I've finally got it (by the way I think I'm actually starting to understand some of this). I will post the code for creating a link to another access database, just in case someone else is ever trying to figure this out. The following will create a link named "Link" once you replace the variable strConnect with the path of your database and strSourceTable with the name of the table in that database you want to link to:

Dim dbsTemp As Database
Dim tdfLinked As TableDef
Dim strTable As String
Dim strConnect As String
Dim strSourceTable As String

Set dbsTemp = CurrentDb

'Fill in the name of the link
strTable = "Link"
'Fill in the path of the database you want to link to
strConnect = "T:\logsheets\Employees\kbishop.mdb"
'Fill in the name of the table you want to link to
strSourceTable = "Storage"

Set tdfLinked = dbsTemp.CreateTableDef(strTable)

tdfLinked.Connect = ";DATABASE=" & strConnect
tdfLinked.SourceTableName = strSourceTable
dbsTemp.TableDefs.Append tdfLinked

[This message has been edited by doulostheou (edited 04-26-2002).]
 
Dude!!

You Rule. Thanks for the code, it works great.
 
I've got to add my take...
This is just too cool.

Here is an easy way to re-link all of your "linked" tables. This will also work if you are rolling a product out and you aren't sure what Server(s) it will eventually end up on. All the Host Company will need to do is enter the "Back End" Connection path into a table.

Here are the steps..
Code:
1) Create a Table (tblConnection)
   a)3 Fields
      i) ConID (AutoNum)
      ii) ServerName (Uniquely Identify Host Server)
      iii) conStr (Full Path String of the Back End DB)

2) Put this code somewhere in a Sub Procedure

Private Sub BuildConnectionBut_Click()

Dim dbConnect As String, finalStr As String, tbl As TableDef

'initialize string to alert user of changes
finalStr = "Connected Tables Are..." & vbCrLf & vbCrLf
'get the connection string of back end server (replace fakeServer w/ value from tblCon
dbConnect = DLookup("[conStr]", "tblCon", "[serverName] = 'fakeServer'")

For Each tbl In CurrentDb.TableDefs 'loop through all tables on front end
   If Not IsNothing(tbl.Connect) Then  'if the table HAS a connection
     Call doConnect(tbl.Name, tbl.Name, dbConnect)  'call the fuction to re-create link
     finalStr = finalStr & tbl.Name & vbTab & tbl.SourceTableName & vbCrLf 'build string
   End If
Next tbl
MsgBox finalStr  'print out string for user visual
 
Set tbl = Nothing 

End Sub

'Here is the procedure for building individual table connections

Public Function doConnect(linkName As String, sourceName As String, dbConnect As String)
 Dim tbl As TableDef, dbsTemp As DAO.Database, tblName As TableDef
 Set dbsTemp = CurrentDb
 
 For Each tblName In dbsTemp.TableDefs  'loop through tables
    If tblName.Name = linkName Then  'if the table (w/ link) already exists
      DoCmd.DeleteObject acTable, linkName  'delete the current table
    End If
 Next tblName
 
 Set tbl = dbsTemp.CreateTableDef(linkName)  'create new table (w/ link)
 tbl.Connect = ";DATABASE=" & dbConnect  'set connection db
 tbl.SourceTableName = sourceName  'set source table name (from back end)
 dbsTemp.TableDefs.Append tbl   'add the tabledef to front end
 
 Set tbl = Nothing
 Set dbsTemp = Nothing
 Set tblName = Nothing
 
End Function

'Here is the Code for the IsNothing Function

Function IsNothing(varToTest As Variant) As Integer
'  Tests for a "logical" nothing based on data type
'  Empty and Null = Nothing
'  Number = 0 is Nothing
'  Zero length string is Nothing
'  Date/Time is never Nothing

    IsNothing = True

    Select Case VarType(varToTest)
        Case vbEmpty
            Exit Function
        Case vbNull
            Exit Function
        Case vbBoolean
            If varToTest Then IsNothing = False
        Case vbByte, vbInteger, vbLong, vbSingle, vbDouble, vbCurrency
            If varToTest <> 0 Then IsNothing = False
        Case vbDate
            IsNothing = False
        Case vbString
            If (Len(varToTest) <> 0 And varToTest <> " ") Then IsNothing = False
    End Select

End Function

That's it. This will refresh all of your links. This will be a good thing to use in the even that you have to roll out a new Revision of your front end Db. It gives you an easy way to make sure everyone has the newest db and assures that all of their links are up to date.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom