Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default WorkbookBeforeSave Event - check required fields before saving

I am not very good with code, I am trying to Save a workbook, but prior to
saving I want it to check certain fields to ensure they are filled in. Below
is the code I am using, but doesn't seem to work. Any Suggestions??

Linda


Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
a = MsgBox("Do you really want to save the workbook?", vbYesNo)
If a = vbYes Then SaveAsUI = True
If TextBox8 = "" Then
MsgBox "Please enter Submitting Agency Name"
Exit Sub
End If
If TextBox1 = "" Then
MsgBox "Please enter Accounting Unit Code (7 Digits)"
Exit Sub
End If
If TextBox4 = "" Then
MsgBox "Please enter Task Coordinator Name"
Exit Sub
End If
If TextBox5 = "" Then
MsgBox "Please enter Task Coordinator Telephone Number"
Exit Sub
End If
If TextBox6 = "" Then
MsgBox "Please enter Task Coordinator Email Address"
Exit Sub
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default WorkbookBeforeSave Event - check required fields before saving

On Mar 25, 12:23*pm, LRay67 wrote:
I am not very good with code, I am trying to Save a workbook, but prior to
saving I want it to check certain fields to ensure they are filled in. *Below
is the code I am using, but doesn't seem to work. *Any Suggestions??

Linda

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
* * * * ByVal SaveAsUI As Boolean, Cancel As Boolean)
* a = MsgBox("Do you really want to save the workbook?", vbYesNo)
* * If a = vbYes Then SaveAsUI = True
*If TextBox8 = "" Then
* * MsgBox "Please enter Submitting Agency Name"
* * Exit Sub
* * End If
If TextBox1 = "" Then
* * MsgBox "Please enter Accounting Unit Code (7 Digits)"
* * Exit Sub
* * End If
*If TextBox4 = "" Then
* * MsgBox "Please enter Task Coordinator Name"
* * Exit Sub
* * End If
*If TextBox5 = "" Then
* * MsgBox "Please enter Task Coordinator Telephone Number"
* * Exit Sub
* * End If
*If TextBox6 = "" Then
* * MsgBox "Please enter Task Coordinator Email Address"
* * Exit Sub
* * End If
*End Sub


Try this ....

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim bnSave as Boolean

a = MsgBox("Do you really want to save the workbook?", vbYesNo)
If a = vbYes Then bnSave = True

If TextBox8 = "" Then
MsgBox "Please enter Submitting Agency Name"
Exit Sub
End If

If TextBox1 = "" Then
MsgBox "Please enter Accounting Unit Code (7 Digits)"
Exit Sub
End If

If TextBox4 = "" Then
MsgBox "Please enter Task Coordinator Name"
Exit Sub
End If

If TextBox5 = "" Then
MsgBox "Please enter Task Coordinator Telephone Number"
Exit Sub
End If

If TextBox6 = "" Then
MsgBox "Please enter Task Coordinator Email Address"
Exit Sub
End If

If bnSave = True then
ActiveWorkbook.Save
End if

End Sub




Does that help??

Chris
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default WorkbookBeforeSave Event - check required fields before saving

Chris, I am not even getting the 1st message box "Do you really want to save
the workbook?" Nothing is working....Is there a particular place in the code
sheet that I am to place the Private Sub App_WorkbookBeforeSave statement?
Help -Thanks

"cht13er" wrote:

On Mar 25, 12:23 pm, LRay67 wrote:
I am not very good with code, I am trying to Save a workbook, but prior to
saving I want it to check certain fields to ensure they are filled in. Below
is the code I am using, but doesn't seem to work. Any Suggestions??

Linda

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
a = MsgBox("Do you really want to save the workbook?", vbYesNo)
If a = vbYes Then SaveAsUI = True
If TextBox8 = "" Then
MsgBox "Please enter Submitting Agency Name"
Exit Sub
End If
If TextBox1 = "" Then
MsgBox "Please enter Accounting Unit Code (7 Digits)"
Exit Sub
End If
If TextBox4 = "" Then
MsgBox "Please enter Task Coordinator Name"
Exit Sub
End If
If TextBox5 = "" Then
MsgBox "Please enter Task Coordinator Telephone Number"
Exit Sub
End If
If TextBox6 = "" Then
MsgBox "Please enter Task Coordinator Email Address"
Exit Sub
End If
End Sub


Try this ....

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim bnSave as Boolean

a = MsgBox("Do you really want to save the workbook?", vbYesNo)
If a = vbYes Then bnSave = True

If TextBox8 = "" Then
MsgBox "Please enter Submitting Agency Name"
Exit Sub
End If

If TextBox1 = "" Then
MsgBox "Please enter Accounting Unit Code (7 Digits)"
Exit Sub
End If

If TextBox4 = "" Then
MsgBox "Please enter Task Coordinator Name"
Exit Sub
End If

If TextBox5 = "" Then
MsgBox "Please enter Task Coordinator Telephone Number"
Exit Sub
End If

If TextBox6 = "" Then
MsgBox "Please enter Task Coordinator Email Address"
Exit Sub
End If

If bnSave = True then
ActiveWorkbook.Save
End if

End Sub




Does that help??

Chris

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default WorkbookBeforeSave Event - check required fields before saving

On Mar 25, 1:11*pm, LRay67 wrote:
Chris, I am not even getting the 1st message box "Do you really want to save
the workbook?" Nothing is working....Is there a particular place in the code
sheet that I am to place the Private Sub App_WorkbookBeforeSave statement? *
Help *-Thanks



"cht13er" wrote:
On Mar 25, 12:23 pm, LRay67 wrote:
I am not very good with code, I am trying to Save a workbook, but prior to
saving I want it to check certain fields to ensure they are filled in. *Below
is the code I am using, but doesn't seem to work. *Any Suggestions??


Linda


Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
* * * * ByVal SaveAsUI As Boolean, Cancel As Boolean)
* a = MsgBox("Do you really want to save the workbook?", vbYesNo)
* * If a = vbYes Then SaveAsUI = True
*If TextBox8 = "" Then
* * MsgBox "Please enter Submitting Agency Name"
* * Exit Sub
* * End If
If TextBox1 = "" Then
* * MsgBox "Please enter Accounting Unit Code (7 Digits)"
* * Exit Sub
* * End If
*If TextBox4 = "" Then
* * MsgBox "Please enter Task Coordinator Name"
* * Exit Sub
* * End If
*If TextBox5 = "" Then
* * MsgBox "Please enter Task Coordinator Telephone Number"
* * Exit Sub
* * End If
*If TextBox6 = "" Then
* * MsgBox "Please enter Task Coordinator Email Address"
* * Exit Sub
* * End If
*End Sub


Try this ....


Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
* * * * ByVal SaveAsUI As Boolean, Cancel As Boolean)


Dim bnSave as Boolean


* a = MsgBox("Do you really want to save the workbook?", vbYesNo)
* * If a = vbYes Then bnSave = True


*If TextBox8 = "" Then
* * MsgBox "Please enter Submitting Agency Name"
* * *Exit Sub
End If


*If TextBox1 = "" Then
* * *MsgBox "Please enter Accounting Unit Code (7 Digits)"
* * *Exit Sub
End If


If TextBox4 = "" Then
* * *MsgBox "Please enter Task Coordinator Name"
* * *Exit Sub
End If


If TextBox5 = "" Then
* * *MsgBox "Please enter Task Coordinator Telephone Number"
* * *Exit Sub
End If


If TextBox6 = "" Then
* * *MsgBox "Please enter Task Coordinator Email Address"
* * *Exit Sub
End If


If bnSave = True then
* * *ActiveWorkbook.Save
End if


End Sub


Does that help??


Chris- Hide quoted text -


- Show quoted text -


Aha! Place this in the "ThisWorkbook" area:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Dim bnSave As Boolean

a = MsgBox("Do you really want to save the workbook?", vbYesNo)
If a = vbYes Then bnSave = True


If TextBox8 = "" Then
MsgBox "Please enter Submitting Agency Name"
Exit Sub
End If


If TextBox1 = "" Then
MsgBox "Please enter Accounting Unit Code (7 Digits)"
Exit Sub
End If


If TextBox4 = "" Then
MsgBox "Please enter Task Coordinator Name"
Exit Sub
End If


If TextBox5 = "" Then
MsgBox "Please enter Task Coordinator Telephone Number"
Exit Sub
End If


If TextBox6 = "" Then
MsgBox "Please enter Task Coordinator Email Address"
Exit Sub
End If

If bnSave = True Then
SaveAsUI = True
End If


End Sub
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet.Unprotect within WorkbookBeforeSave event fails if Save Dean Meyer[_2_] Excel Programming 5 March 30th 09 04:19 PM
how to have fields to be required Mandatory fields in Excel Excel Worksheet Functions 1 June 6th 08 10:41 PM
Worksheet.Unprotect within WorkbookBeforeSave event fails if Save initiated by VB Dean Meyer Excel Programming 3 June 8th 07 12:30 AM
Required fields Brian Boguhn Excel Programming 5 January 10th 06 05:51 PM
Required fields Emily Excel Discussion (Misc queries) 1 June 23rd 05 12:59 AM


All times are GMT +1. The time now is 08:44 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"