Below is a copy of the function I use to import new tables from “NewDB.mdb” into my program. It works fine, however, I need the user to rename this DB to something new after it is imported. I’m not sure what I have to do or where in the code I need to put it.
Could use your help. Thank you…
Sub ImportTables()
Dim db As Database
Dim tdf As TableDef
Dim dlgSaveAs As FileDialog
Dim strFilePathName As String
Set dlgSaveAs = Application.FileDialog(msoFileDialogOpen)
Application.FileDialog(FileDialogType:=msoFileDialogSaveAs)
dlgSaveAs.Title = "Select backup file"
dlgSaveAs.AllowMultiSelect = False
If dlgSaveAs.Show = True Then
strFilePathName = dlgSaveAs.SelectedItems(dlgSaveAs.SelectedItems.Count)
Else
'User clicked cancel
Exit Sub
End If
Set db = OpenDatabase(strFilePathName)
For Each tdf In db.TableDefs
If Not (Left(tdf.Name, 4)) = "MSys" Then
On Error Resume Next
Access.DoCmd.TransferDatabase acImport, "Microsoft Access", strFilePathName, acTable, tdf.Name, tdf.Name, False
Else
End If
Next tdf
Set db = Nothing
End Sub
Could use your help. Thank you…
Sub ImportTables()
Dim db As Database
Dim tdf As TableDef
Dim dlgSaveAs As FileDialog
Dim strFilePathName As String
Set dlgSaveAs = Application.FileDialog(msoFileDialogOpen)
Application.FileDialog(FileDialogType:=msoFileDialogSaveAs)
dlgSaveAs.Title = "Select backup file"
dlgSaveAs.AllowMultiSelect = False
If dlgSaveAs.Show = True Then
strFilePathName = dlgSaveAs.SelectedItems(dlgSaveAs.SelectedItems.Count)
Else
'User clicked cancel
Exit Sub
End If
Set db = OpenDatabase(strFilePathName)
For Each tdf In db.TableDefs
If Not (Left(tdf.Name, 4)) = "MSys" Then
On Error Resume Next
Access.DoCmd.TransferDatabase acImport, "Microsoft Access", strFilePathName, acTable, tdf.Name, tdf.Name, False
Else
End If
Next tdf
Set db = Nothing
End Sub