Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with BeforeSave 1

Status
Not open for further replies.

jnowles

Technical User
Jun 4, 2003
16
US
Hi,

I have just wrote my first piece of VBA code and while it works the MsgBox appears twice. It pops up, you hit OK, it pops up again you hit OK again. What wrong?


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Call SaveWorkbook
a = MsgBox("You are now saving a Backup to C:\Alldata\BudgetBackUp\")
End Sub
 
Just a guess, with the routine -> Call SaveWorkbook <- it appears as if you intend to copy a ( second copy ) back up file. in wich case the before save routine is being called twice and accordingly gives two msgbox's out on the screen.

If so try blocking the second instance...

Code:
Dim sving as boolean

Private Sub Workbook_BeforeSave( _
            ByVal SaveAsUI As Boolean, _
            Cancel As Boolean)

       If(sving = False)Then
            sving = True
            Call SaveWorkbook
            a = MsgBox("You are now saving a Backup to
            C:\Alldata\BudgetBackUp\")
            sving = False
            End If
End Sub

Like I said, just a guess.
 
Hi Melinx,

That helped immensely, Thanks for helping me identify the problem. Your code worked perfectly when I removed the MsgBox statement, so I put the message in the SaveWorkBook routine.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top