Restore Button (1 Viewer)

Borror

New member
Local time
Today, 01:45
Joined
Jul 9, 2017
Messages
5
Please, This is a feedback. I used the codes below to write up the restore button, it responds alright but it does really restore the Access objects . My expectation is that by the punch of the restore button, the Access Objects in the software will be deleted and replaced by the Access Objects in the backup file or if the software is blank will updated with the objects in the backup file.
Please, check out the codes and see if you help to edit and so that works as it should.


Private Sub cmdRestore_Click()
Dim strBackup As String
Dim strFullBackup As String
Dim strExt As String
'* do some validataion before executing
If Trim(Me.txtFileName & "") <> "" Then
If Dir(Me.txtFileName) <> "" Then
strExt = (Me.txtFileName)
strBackup = "Backup" & Format(Now(), "_ddmmyyyy_nnss") & strExt
strFullBackup = CurrentProject.Path & "" & strBackup

'* rename original database

'* restore backup
FileCopy Me.txtFileName, CurrentProject.Path & "" & DLookup("OriginalName", "tblBackUpDB")

'* update table
CurrentDb.Execute "Update tblBackUpDB Set [FromBackupName]=" & Chr(34) & (Me.txtFileName) & Chr(34) & ", " & _
"[NewBackUpName] = " & Chr(34) & strBackup & Chr(34) & ", [Cancelled]=0;"

MsgBox "Congratulations !!! Successfully restored database from " & (Me.txtFileName)
MsgBox "Have A Nice Day"
Else
MsgBox "Path or filename not found.", vbOKOnly, "Restore"
Me.txtFileName.SetFocus
End If
Else
MsgBox "Nothing to restore", vbOKOnly, "Restore"

End If
End Sub
 

Cronk

Registered User.
Local time
Today, 18:45
Joined
Jul 4, 2013
Messages
2,774
When you say you want to "restore the Access objects", what do you define as Access objects?

I doubt if anyone on this forum does not backup their work other than by saving a copy of the mdb or accdb file, and restoring the whole file if required. That certainly is the purpose of the code you quote, which was given to you by Arnelgp in another thread started by you on the same topic.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:45
Joined
May 7, 2009
Messages
19,246
if you are just restoring the Tables from the backup a simple

SELECT * INTO tableName FROM tableName IN 'externalDBPath';

will do the work.
 

Attachments

  • AnotherRestorer.zip
    24 KB · Views: 85

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 03:45
Joined
Feb 28, 2001
Messages
27,314
Fine point on the feedback:

Code:
MsgBox "Congratulations !!! Successfully restored database from " & (Me.txtFileName)
MsgBox "Have A Nice Day"

will interrupt you twice with message boxes whereas

Code:
MsgBox "Congratulations !!! Successfully restored database from " & (Me.txtFileName), _
    vbOKOnly, "Have A Nice Day"

will only interrupt the flow of your work once.

As a second note: When posting code use the code symbol (# on the quick-reply or advanced dialog box's menu bar) to put code tags around the code. Helps set it aside and makes it easier for us to read so that we can advise you better on your next question involving code.

As a third note:

Code:
strBackup = "Backup" & Format(Now(), "_ddmmyyyy_nnss") & strExt

will specify a backup file time-tagged for the exact time that you form the name (and by the way, if you are doing this, you PROBABLY want _hhnnss since you left off the hours). The name you form will then look like "Backup_ddmmyyyy_hhnnssMORE TEXT" beccause you are tacking on strEXT. If that is supposed to be a file extension (which WOULD make sense here), be sure that strExt includes the dot (.) character. But typically, Access backups have the same extension as the original file but just have date (only) in the backup's file name. So is this backup one that you generate yourself (thus having a non-standard name)?

I will also state another concern: This will ONLY work if the problem is that your data contains errors that technically are not forms of structural corruption. If the data files are truly corrupted, this might not work at all because the database could in that case refuse to operate. The database HAS to be viable for this button to remain functional. The typical Access response to true corruption is to simply try to auto-recover, and if that fails it shuts down. In that case, a manual restoration will be all that you have available to you.
 
Last edited:

Users who are viewing this thread

Top Bottom