beforesave

D

Doug

I am working on a form for our salesmen. I have a series of checkboxes that
are available and when one is checked on or enabled the others are disabled.
What I want to do with two of these when the salesman tries to save the form
is have it check for these two checkboxes to see if one is on/enabled and if
so then check a cell to make sure it has been filled out. If not then you get
a message asking you to fill in the requirement. The code is on ThisWorkbook,
I would appreciate any help.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
'In the "Enclosure" section of the form, looks at checkboxes for Sound
Attenuated, Super Sound Attenuated, and cell H33. If one is checked on and
H33 is blank then don't allow Save.

If cbSA.Enabled = True And Range("H33").Value = "" Then
Cancel = True
If cbSSA.Enabled = True And Range("H33").Value = "" Then
Canel = True

MsgBox("You have not specified a sound attenuation requirement.") &
("This sheet will not be saved until you furnish this information" vbOKOnly)
If a = vbOKOnly Then Cancel = True

End If
End If
End Sub
 
D

Doug

Patrick,
I commented out what I had and copied and pasted your code. Initially I was
getting "Compile Error: Expected: list separator or )". I played with the
parenthesis and got that worked out by removing all of them. Now I am getting
"Run-time Error '424': Object required" and when I pick the debug button it
highlights the "If" line of code. I am also wondering if I don't have to set
the checkboxes.enabled to true or false? Thanks for you help!
 
P

Patrick Molloy

yes, i stuffed the parenthesis in the msgbox when i got rid of the IF
statement that was there originally. Apologies for that, me bad.

try preceding the cb objects with the sheet name eg
sheet1.cbSA
 
D

Doug

Patrick, you are the BOM. Thank you so much!

Patrick Molloy said:
yes, i stuffed the parenthesis in the msgbox when i got rid of the IF
statement that was there originally. Apologies for that, me bad.

try preceding the cb objects with the sheet name eg
sheet1.cbSA
 
D

Doug

I spoke a little to soon. If neither of the checkboxes are enabled then I
want to be able to save the workbook. I still get the message and I presume
it is not saving. Sorry. I know just enough of this to be dangerous but that
is about it. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top