Dear Experts,
I have a code that my client clicks to create backups with time stamp folders successfully. I am now working on a code to restore the most recent backup in the event that the current database is destroyed in whatever way imaginable.
I compile my application with a compiler which allows my client to take charge of the installation and maintenance. Because the client takes care of the installation, I do not use static file path in my code.
In the event that the current application has to be re-installed for whatever reason, I want the client to be able to do the following:
1. Install a new application with empty tables
2. Use a restore button within the new application to call for restoration
3. The restore processes are:
a. Delete all tables in the new installation
b. Open file picker to locate the most recent backup copy
c. Import all tables from the backup to the new empty installation
I have error at the point of picking the file. I currently have error: 3055 Not a valid file name. The following are my CODEs.
‘--------------------------------------------------------------------
‘1. This CODE opens the file picker
‘-----------------------------------------------------
Function FileDialog()
On Error GoTo Exit_Function
Dim objDialog As Object
Dim vrtSelectedItem As Variant
Dim path As String
Set objDialog = Application.FileDialog(3)
With objDialog
.AllowMultiSelect = False
.Title = "Please select a file to import"
.Show
If .SelectedItems.Count = 0 Then
MsgBox "No file selected.", vbOKOnly, " Select File"
Else
Call ImportTables
End If
End With
Exit_Function:
Exit Function
End Function
‘-----------------------------------------------------
‘2. This CODE initiates the table importation
‘--------------------------------------------------------
Function ImportTables()
On Error GoTo ImportTable_Err
Dim db As Database
Dim tdf As TableDef
Dim DBPath As String
DBPath = CurrentProject.path & "\Backups"
Set db = OpenDatabase(DBPath)
For Each tdf In db.TableDefs
If Not (Left(tdf.Name, 4)) = "MSys" Then
On Error Resume Next
Access.DoCmd.TransferDatabase acImport, "Microsoft Access", DBPath, acTable, tdf.Name, tdf.Name, False
Else
End If
Next tdf
Set db = Nothing
ImportTable_Exit:
Exit Function
ImportTable_Err:
MsgBox Error$
Resume ImportTable_Exit
End Function
‘----------------------------------------------------------
I get error 3055 Not a Valid File Name at:
Set db = OpenDatabase(DBPath)
I have Googled everywhere I can but no previous solution works for me.
Any assistance will be very much appreciated.
Shafiu.
I have a code that my client clicks to create backups with time stamp folders successfully. I am now working on a code to restore the most recent backup in the event that the current database is destroyed in whatever way imaginable.
I compile my application with a compiler which allows my client to take charge of the installation and maintenance. Because the client takes care of the installation, I do not use static file path in my code.
In the event that the current application has to be re-installed for whatever reason, I want the client to be able to do the following:
1. Install a new application with empty tables
2. Use a restore button within the new application to call for restoration
3. The restore processes are:
a. Delete all tables in the new installation
b. Open file picker to locate the most recent backup copy
c. Import all tables from the backup to the new empty installation
I have error at the point of picking the file. I currently have error: 3055 Not a valid file name. The following are my CODEs.
‘--------------------------------------------------------------------
‘1. This CODE opens the file picker
‘-----------------------------------------------------
Function FileDialog()
On Error GoTo Exit_Function
Dim objDialog As Object
Dim vrtSelectedItem As Variant
Dim path As String
Set objDialog = Application.FileDialog(3)
With objDialog
.AllowMultiSelect = False
.Title = "Please select a file to import"
.Show
If .SelectedItems.Count = 0 Then
MsgBox "No file selected.", vbOKOnly, " Select File"
Else
Call ImportTables
End If
End With
Exit_Function:
Exit Function
End Function
‘-----------------------------------------------------
‘2. This CODE initiates the table importation
‘--------------------------------------------------------
Function ImportTables()
On Error GoTo ImportTable_Err
Dim db As Database
Dim tdf As TableDef
Dim DBPath As String
DBPath = CurrentProject.path & "\Backups"
Set db = OpenDatabase(DBPath)
For Each tdf In db.TableDefs
If Not (Left(tdf.Name, 4)) = "MSys" Then
On Error Resume Next
Access.DoCmd.TransferDatabase acImport, "Microsoft Access", DBPath, acTable, tdf.Name, tdf.Name, False
Else
End If
Next tdf
Set db = Nothing
ImportTable_Exit:
Exit Function
ImportTable_Err:
MsgBox Error$
Resume ImportTable_Exit
End Function
‘----------------------------------------------------------
I get error 3055 Not a Valid File Name at:
Set db = OpenDatabase(DBPath)
I have Googled everywhere I can but no previous solution works for me.
Any assistance will be very much appreciated.
Shafiu.