Msgbox option

cooh23

Registered User.
Local time
Yesterday, 18:24
Joined
Dec 5, 2007
Messages
169
Hi Everyone,

I have a message box that says "Backup complete" but it has an Ok button. Is there a way for the user to see the message and then close without hitting the ok button?

here's my code

Code:
MsgBox "Backup was successful and saved", vbInformation, "Backup Completed"

Thank you
 
So, you just want a message displayed that says "Backup Complete" for X amount of time, and then the message box closes itself?
 
So, you just want a message displayed that says "Backup Complete" for X amount of time, and then the message box closes itself?

That is correct. The code is part of a module that backs up my database on close. But for some reason, backup doesn't work if i remove the msgbox line.

here's the code
Code:
Public Function BackupAndZipit() 

'This function will allow you to copy a db that is open, 
'rename the copied db and zip it up to anther folder. 

'You must set a reference to the 'Microsoft Scripting Runtime' for the CopyFile piece to work! 

'Thanks to Ricky Hicks for the .CopyFile code 

Dim fso As FileSystemObject 

Dim sSourcePath As String 
Dim sSourceFile As String 
Dim sBackupPath As String 
Dim sBackupFile As String 

sSourcePath = "C:\Database\" 
sSourceFile = "MyDB.mdb" 
sBackupPath = "C:\Database\Backups\" 
sBackupFile = "BackupDB_" & Format(Date, "mmddyyyy") & "_" & Format(Time, "hhmmss") & ".mdb" 

Set fso = New FileSystemObject 
fso.CopyFile sSourcePath & sSourceFile, sBackupPath & sBackupFile, True 
Set fso = Nothing 

Dim sWinZip As String 
Dim sZipFile As String 
Dim sZipFileName As String 
Dim sFileToZip As String 

sWinZip = "C:\Program Files\WinZip\WinZip32.exe" 'Location of the WinZip program 
sZipFileName = Left(sBackupFile, InStr(1, sBackupFile, ".", vbTextCompare) - 1) & ".zip" 
sZipFile = sBackupPath & sZipFileName 
sFileToZip = sBackupPath & sBackupFile 

Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide) 

Beep 
MsgBox "Backup was successful and saved @ " & Chr(13) & Chr(13) & sBackupPath & Chr(13) & Chr(13) & "The backup file name is " & Chr(13) & Chr(13) & sZipFileName, vbInformation, "Backup Completed" 

If Dir(sBackupPath & sBackupFile) <> "" Then Kill (sBackupPath & sBackupFile) 

End Function

The code is 3 lines from the bottom.

Thanks
 
A standard message box won't do that. We can use a simple timer event though, so the solution is this:

1) Make a new form (f_BackupMessage or some name that makes sense to you).

2) On the form, put just one label in the center that says, "Backup Complete" or whatever message you want.

3) In the form's code view, copy/paste in this:

Code:
Option Compare Database
Option Explicit

Dim TimeToClose As Date

Private Sub Form_Open(Cancel As Integer)

    TimeToClose = DateAdd("s", [COLOR="red"]5[/COLOR], Time())
    
End Sub

Private Sub Form_Timer()

    If Time() >= TimeToClose Then
        DoCmd.Close acForm, "[COLOR="Red"]f_BackupMessage[/COLOR]"
    End If

End Sub

4) Replace the number in red with the number of seconds you want the form to stay open. Replace the form name in red with whatever you've named this new form.

5) Set the Timer Interval property of the form to 1000. This will check the form to see if it should close itself every second.

6) Save the form and close it.

7) Call it in your code like this:

Code:
.
.
.
Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide) 

Beep 
[COLOR="red"]DoCmd.OpenForm "f_BackupMessage",acNormal,,,,acDialog[/COLOR]
If Dir(sBackupPath & sBackupFile)...
.
.
.

That's it.
 
Last edited:
A standard message box won't do that. We can use a simple timer event though, so the solution is this:

1) Make a new form (f_BackupMessage or some name that makes sense to you).

2) On the form, put just one label in the center that says, "Backup Complete" or whatever message you want.

3) In the form's code view, copy/paste in this:

Code:
Option Compare Database
Option Explicit

Dim TimeToClose As Date

Private Sub Form_Open(Cancel As Integer)

    TimeToClose = DateAdd("s", [COLOR="red"]5[/COLOR], Time())
    
End Sub

Private Sub Form_Timer()

    If Time() >= TimeToClose Then
        DoCmd.Close acForm, "[COLOR="Red"]f_BackupMessage[/COLOR]"
    End If

End Sub

4) Replace the number in red with the number of seconds you want the form to stay open. Replace the form name in red with whatever you've named this new form.

5) Set the Timer Interval property of the form to 1000. This will check the form to see if it should close itself every second.

6) Save the form and close it.

7) Call it in your code like this:

Code:
.
.
.
Call Shell(sWinZip & " -a " & sZipFile & " " & sFileToZip, vbHide) 

Beep 
[COLOR="red"]DoCmd.OpenForm "f_BackupMessage",acNormal,,,,acDialog[/COLOR]
If Dir(sBackupPath & sBackupFile)...
.
.
.

That's it.

Hello,

The code above works great but I seem to have a slight problem when it's combined with another code.

I have a module that detects to see if a certain file is present, if not, the database automatically shuts down(let's call this maintenance module)
Once the maintenance module shuts down the database, the backup module fires up and backs up the data.

When I close the DB normally (meaning, not closed by the maintenance module) it works okay. The problem I have is that when it is closed by the maintenance module, the DB closes but the backup message form remains open and cannot be closed unless I go to the taskmanager and end task.

I am not sure what is going on. Please advise.

Thank you,
 
By the way: Another option is to display your message in the Status bar: people see it's backuped and you don't need all the code to make the message appear/disapear... it's what statusbars are designed for, imho.

For your specified problem, If I understand you correctly, In the form that created the "f_BackupMessage" you'll have to place
Code:
Private Sub Form_Close()
     DoCmd.Close acForm, "f_BackupMessage"
End Sub

Regardless your timer, the Message will be closed... you may want to destroy your timer too if you explicitly created it.
 

Users who are viewing this thread

Back
Top Bottom