Hi eveyone.
I'm trying to create a button on a form to link to a backend file.
this is the code I have so far:
Code:
Function getFileNameOpen(path) As String
Dim f As Object
Dim varFile As Variant
Set f = Application.FileDialog(3)
With f
f.AllowMultiSelect = True
f.Filters.Clear
f.Filters.Add "Access Databases", "*.accdb"
f.Filters.Add "All Files", "*.*"
If f.show = -1 Then
For Each varFile In f.SelectedItems
file = varFile
Next varFile
End If
End With
path = file
End Function
This function opens a browser window to get the file path.
Code:
Function OpenFile()
Call getFileNameOpen(path)
Dim db As Database
Dim td As TableDef
Dim WS As Workspace
Dim i As Integer
Dim ListOfNames()
i = 0
ReDim ListOfNames(i)
Set WS = CreateWorkspace("DBtoReadTables", "admin", "", dbUseJet)
Set db = WS.OpenDatabase(path, True)
For Each td In db.TableDefs
If Left(td.name, 4) <> "MSys" Then
ListOfNames(i) = td.name
i = i + 1
ReDim Preserve ListOfNames(i)
Else
End If
Next td
db.Close
Set db = Nothing
Set WS = Nothing
Dim dbsTemp As Database
Dim strMenu As String
Dim strInput As String
Dim tbname As Variant
Dim name As String
Set dbsTemp = CurrentDb
For Each tbname In ListOfNames
name = tbname
ConnectOutput dbsTemp, _
name, _
Database = path, _
name
Next
End Function
Sub ConnectOutput(dbsTemp As Database, _
strTable As String, strConnect As String, _
strSourceTable As String)
Dim tdfLinked As TableDef
Set tdfLinked = dbsTemp.CreateTableDef(strTable)
tdfLinked.Connect = strConnect
tdfLinked.SourceTableName = strSourceTable
dbsTemp.TableDefs.Append tdfLinked
End Sub
this open gets the name of all the tables an puts them into an array
them loops through the array to link each table name
I can't figure out what is wrong
Can someone help me out please