File picker to select Backup database to Restore: error 3055, Not a valid file name (1 Viewer)

sshafiu

Registered User.
Local time
Today, 15:26
Joined
Dec 25, 2018
Messages
13
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.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,125
Well, at that point the path is just to a folder, not an Access file. Wouldn't you want to use the file selected by the user?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,125
Here's the relevant part of my template code. I would think you'd want to pass varFile to the other function and use that:

Code:
       If .Show = True Then
          For Each varFile In .SelectedItems
             'do what you need with the file
             Debug.Print varFile
          Next
       Else
          MsgBox "You clicked Cancel in the file dialog box."
       End If
 

sshafiu

Registered User.
Local time
Today, 15:26
Joined
Dec 25, 2018
Messages
13
Thanks Paul.

I want to use the file selected but, when I clicked open, I bumped into that error.

Sorry for my low-level.

In your posted code, what do I put in that line after the selected item to get it to open the file to start the importation?
 

June7

AWF VIP
Local time
Today, 07:26
Joined
Mar 9, 2014
Messages
5,472
I don't see a filename in the constructed path.

Please post lengthy code within CODE tags to retain indentation and readability.

And now I see Paul has already posted.
 

sshafiu

Registered User.
Local time
Today, 15:26
Joined
Dec 25, 2018
Messages
13
Sorry here is it in code tags. I hope you can see it better now.

‘--------------------------------------------------------------------
‘1. This CODE opens the file picker
‘-----------------------------------------------------
Code:
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
‘--------------------------------------------------------
Code:
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
‘----------------------------------------------------------
 

Voyager

Registered User.
Local time
Today, 20:56
Joined
Sep 7, 2017
Messages
95
Hi,
Gone through your link. Very useful have bookmarked it and even taken few printout as many of these are frequently used.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:26
Joined
Aug 30, 2003
Messages
36,125
Glad it helped you!
 

Users who are viewing this thread

Top Bottom