|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Importing backend automatically with VBA
For a database being used in different offices, I want to provide a config page within the DB App itself so that the user can specify a custom path for the database backend for linking.
I've been messing around with it and am able to link to a backend, if I specify in vba the table names from the back end. I'd rather not do this. I'm also able to load the backend (importing it, it seems) through VBA. If I check the tables for a connect status, it says it's zero, which is what I get if the tables are not linked. What I want to do is use VBA to link every table in the backend without having to know the names of the tables. If I try to do a for loop for each tbl.name after loading the database with : 'Set wrkAcc = CreateWorkspace("", "admin", "", dbUseJet) 'Set dbs = wrkAcc.OpenDatabase("C:\testdatabase_be.accdb") It doesn't seem to want to work. I suppose I need a way to get each table name before linking all the tables with code such as: Code:
Dim tdf As TableDef Dim strSourceName As String Dim strLocalName As String Dim strSourceDatabase As String With CurrentDb Set tdf = .CreateTableDef(strLocalName) tdf.SourceTableName = strSourceName tdf.Connect = ";DATABASE=" & strSourceDatabase .TableDefs.Append tdf .Close End With ... but with the above, the database is never loaded/read to get the names so tables must be known; however, when I do load (import?) the database, I can't import the tables as such. I think I need to open the database, get the names, close it (doesn't seem to be the right word) and then use that info to start linking it. Any suggestions? |
|
#2
|
|||
|
|||
|
Are these users accessing the same backend stored on a network server? Use UNC (Universal Naming Convention) to link tables then distribute the frontend to users. This method refers to the server name in directory path. Must use code to set the links. Here is example from my project. Fritz is the server name.
Code:
Public Sub NormalizeTableLinks()
'Easier relinking of tables when cases are different in paths, etc.
'Use the variables provided to do the manipulations desired
Dim td As TableDef
Dim db As DAO.Database
Dim strOld As String
Dim strNew As String
'replace the following strings as needed
strOld = "M:\Data\LabData.accdb"
strNew = "\\Fritz\admin\Materials Lab\Lab Database\Data\LabData.accdb"
'strOld = "M:\Data\DBASE"
'strNew = "\\Fritz\admin\Materials Lab\Lab Database\Data\DBASE"
Set db = CurrentDb
For Each td In db.TableDefs
If InStr(td.Connect, strOld) > 0 Then
Debug.Print td.Name
Debug.Print "Old Link: " & td.Connect
td.Connect = Replace(td.Connect, strOld, strNew)
td.RefreshLink
Debug.Print "New Link: " & td.Connect
End If
Next td
db.TableDefs.Refresh
End Sub
Last edited by June7 : October 30th, 2009 at 12:44 PM. |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft Access Help > Importing backend automatically with VBA |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|