Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rename DB after import 1

Status
Not open for further replies.

jac123

Technical User
Apr 25, 2003
19
US
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
 
Look at the Name command in the Access help file for one way of renaming files on disk.

The actual command needs to come after set db = nothing and before End Sub.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top