Hi,
I'm calling a backup procedure which copies the entire subject database to a new location. I'm running this procedure from a Form "Switchboard", which calls a procedure in a separate module, callBackup, which has the procedure makeBackup.
on the form Switchboard:
Private Sub Backup_Click()
makeBackup
End Sub
and the main part of the code in makeBackup is here. I need to unload all forms or I can't copy them:
Function makeBackup()
On Error GoTo Err_backup
Dim backupName As String
Dim backupFile As String
Dim obj As AccessObject
Dim dbs As Object
Set dbs = Application.CurrentProject
For Each obj In Forms
If obj.IsLoaded = True Then
DoCmd.Close acForm, obj.Name
Unload obj
End If
Next obj
If month(Date) < 10 Then
monthForName = "0" & month(Date)
Else: monthForName = month(Date)
End If
If Day(Date) < 10 Then
dayForName = "0" & Day(Date)
Else: dayForName = Day(Date)
End If
backupName = "G:\Business Dev Team\Tools\Leads Database\Backup\koreaLeads\leads_Korea" & Year(Date) & monthForName & dayForName
backupFile = backupName & ".mdb"
backupLoop:
Set dbs = CreateDatabase(backupFile, dbLangGeneral)
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
If obj.IsLoaded = False Then
DoCmd.CopyObject backupName, , acForm, obj.Name
End If
Next
DoCmd.OpenForm "Switchboard"
Stop
DoCmd.CopyObject backupFile, , acTable, "Actions"
DoCmd.CopyObject backupFile, , acTable, "ConDet"
DoCmd.CopyObject backupFile, , acTable, "Ideas"
DoCmd.CopyObject backupFile, , acTable, "Leads Info"
DoCmd.CopyObject backupFile, , acTable, "Minutes"
DoCmd.CopyObject backupFile, , acTable, "PACentres"
DoCmd.CopyObject backupFile, , acTable, "PAHours"
DoCmd.CopyObject backupFile, , acTable, "Reasons"
DoCmd.CopyObject backupFile, , acTable, "Region"
DoCmd.CopyObject backupFile, , acTable, "RegionCode"
DoCmd.CopyObject backupFile, , acTable, "Shiptype"
DoCmd.CopyObject backupFile, , acTable, "Strategy"
DoCmd.CopyObject backupFile, , acTable, "Timeline"
DoCmd.CopyObject backupFile, , acTable, "WinLossReview"
MsgBox "Backup complete"
DoCmd.OpenForm "Switchboard"
Exit_backup:
Exit Function
Err_backup:
MsgBox Err.Description
'backupFile = InputBox("Database " & backupFile & " already exists. Please input a different name", , backupName & "(01).mdb")
'If backupFile = "" Then
' MsgBox "Action cancelled - no backup made"
' GoTo Exit_backup
'End If
'GoTo backupLoop
End Function
The problem is, the program STILL says that form "Switchboard" cannot be loaded or unloaded. Is it because I'm calling makeBackup from within "Switchboard"?
I'm calling a backup procedure which copies the entire subject database to a new location. I'm running this procedure from a Form "Switchboard", which calls a procedure in a separate module, callBackup, which has the procedure makeBackup.
on the form Switchboard:
Private Sub Backup_Click()
makeBackup
End Sub
and the main part of the code in makeBackup is here. I need to unload all forms or I can't copy them:
Function makeBackup()
On Error GoTo Err_backup
Dim backupName As String
Dim backupFile As String
Dim obj As AccessObject
Dim dbs As Object
Set dbs = Application.CurrentProject
For Each obj In Forms
If obj.IsLoaded = True Then
DoCmd.Close acForm, obj.Name
Unload obj
End If
Next obj
If month(Date) < 10 Then
monthForName = "0" & month(Date)
Else: monthForName = month(Date)
End If
If Day(Date) < 10 Then
dayForName = "0" & Day(Date)
Else: dayForName = Day(Date)
End If
backupName = "G:\Business Dev Team\Tools\Leads Database\Backup\koreaLeads\leads_Korea" & Year(Date) & monthForName & dayForName
backupFile = backupName & ".mdb"
backupLoop:
Set dbs = CreateDatabase(backupFile, dbLangGeneral)
Set dbs = Application.CurrentProject
For Each obj In dbs.AllForms
If obj.IsLoaded = False Then
DoCmd.CopyObject backupName, , acForm, obj.Name
End If
Next
DoCmd.OpenForm "Switchboard"
Stop
DoCmd.CopyObject backupFile, , acTable, "Actions"
DoCmd.CopyObject backupFile, , acTable, "ConDet"
DoCmd.CopyObject backupFile, , acTable, "Ideas"
DoCmd.CopyObject backupFile, , acTable, "Leads Info"
DoCmd.CopyObject backupFile, , acTable, "Minutes"
DoCmd.CopyObject backupFile, , acTable, "PACentres"
DoCmd.CopyObject backupFile, , acTable, "PAHours"
DoCmd.CopyObject backupFile, , acTable, "Reasons"
DoCmd.CopyObject backupFile, , acTable, "Region"
DoCmd.CopyObject backupFile, , acTable, "RegionCode"
DoCmd.CopyObject backupFile, , acTable, "Shiptype"
DoCmd.CopyObject backupFile, , acTable, "Strategy"
DoCmd.CopyObject backupFile, , acTable, "Timeline"
DoCmd.CopyObject backupFile, , acTable, "WinLossReview"
MsgBox "Backup complete"
DoCmd.OpenForm "Switchboard"
Exit_backup:
Exit Function
Err_backup:
MsgBox Err.Description
'backupFile = InputBox("Database " & backupFile & " already exists. Please input a different name", , backupName & "(01).mdb")
'If backupFile = "" Then
' MsgBox "Action cancelled - no backup made"
' GoTo Exit_backup
'End If
'GoTo backupLoop
End Function
The problem is, the program STILL says that form "Switchboard" cannot be loaded or unloaded. Is it because I'm calling makeBackup from within "Switchboard"?