Restoring from BackUp

ddrew

seasoned user
Local time
Today, 23:14
Joined
Jan 26, 2003
Messages
911
I have a restore from BackUp form. When the form is activated it runs this code
Code:
Private Sub Form_Activate()

   [COLOR="Red"] Dim strRestore As String

    strRestore = "C:\GungogManager\BackUp\"

    If Len(Dir(strRestore, vbDirectory)) = 0 Then
        MsgBox ("There are no BackUp files available"), vbOKOnly
        Me.btn_Restore.Enabled = False
    Exit Sub[/COLOR]
        Dim FSO As Scripting.FileSystemObject
        Dim SourceFolder As Scripting.Folder
        Dim FileItem As Scripting.File
        Dim r As Long

        Set FSO = New Scripting.FileSystemObject
        Set SourceFolder = FSO.GetFolder("c:\GundogManager\BackUp\")

        For Each FileItem In SourceFolder.Files
            Me.cbo_FileNames.AddItem (FileItem.Name)
        Next FileItem
    End If

End Sub
It was working, but since adding the bit in red its not working. I basicly want it to look for the directory and if it dosent find it the pop up with message, but if the dir does exist then to populate the combo.

Thanks in advance.
 
Is not a lot easier to do this manually ?
 
In theory anything you can do with Access can be done easier with code... less human error.

BUT, we need more info on what "not working" means here. Have you stepped through your code with a breakpoint to see where variables are/aren't working?
 
What should happen is:
The code should populate a combo box with file names from C:\GungogManager\BackUp\. That file is created when a button is pressed on another form to "BackUp the data. If not backup has been created then no file exists.

When this form activates, if the file C:\GungogManager\BackUp\ dosent exist it throws an error because it cant find the file. So, I added the code in red to generate a message that no backups were available and disable the "Restore" button,

As two seperate parts the code works, the problem is that I always get the message popup and the combo dosent populate since adding the red code.
 
I think you are missing an 'Else' after your 'Exit Sub'. It is trying to run the rest of your code IF there is no directory, but exit sub stops it from ever getting there.

Computers are so literal! :p
 
I think you are missing an 'Else' after your 'Exit Sub'. It is trying to run the rest of your code IF there is no directory, but exit sub stops it from ever getting there.

Computers are so literal! :p

Tried but didnt work, thanks
 
I think you are missing an 'Else' after your 'Exit Sub'. It is trying to run the rest of your code IF there is no directory, but exit sub stops it from ever getting there.

David said "I think" because he is a gentile man.
But this is a "must"

Tried but didnt work, thanks
So, the problem is in your red code.

More precise, this part
Len(Dir(strRestore, vbDirectory)) = 0
always return TRUE

so,
Len(Dir(strRestore, vbDirectory)) is always equal to 0

Why ? Because you misspelled the path.

 
How do you know he misspelled the directory? I can't see his C:\ drive... :p

Anyway, put a breakpoint into your code and step through it. You'll see what I mean about the Else line. I think other than that your code looks fine.
 
strRestore = "C:\GungogManager\BackUp\"
and
Set SourceFolder = FSO.GetFolder("c:\GundogManager\BackUp\")
:)
 
Oooh very clever, with your READING and your PAYING ATTENTION...
 
In the Message box do not appear so tall :confused:
 

Users who are viewing this thread

Back
Top Bottom