not save record on close!

G

Guest

Hi,

I have this code in the form and it is not allowed to save anything within
the form unless it has been saved. But my if msgbox isn't working.

Can anyone help my cause? Thx. Sarita

Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("do you want to save?") ,vbYesNo = vbYes
Else
Cancel = True
MsgBox "Update was cancelled", vbOKOnly
End If
End Sub
 
X

xenophon

luscioussarita said:
Hi,

I have this code in the form and it is not allowed to save anything
within the form unless it has been saved. But my if msgbox isn't
working.

Can anyone help my cause? Thx. Sarita

Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("do you want to save?") ,vbYesNo = vbYes
Else
Cancel = True
MsgBox "Update was cancelled", vbOKOnly
End If
End Sub

You don't say how it is "not working," but for starters your syntax is
incorrect. The buttons argument belongs _inside_ the parens, and you'll want
a Then, thus

If MsgBox("Do you want to save changes?", vbYesNo) = vbYes Then

You can also reverse your logic and ditch the Else clause:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("Do you want to save changes?", vbYesNo) = vbNo Then
Cancel = True
MsgBox "Update was cancelled", vbOKOnly
End If
End Sub

Cheers,
Scott
 
C

Carl Rapson

luscioussarita said:
Hi,

I have this code in the form and it is not allowed to save anything within
the form unless it has been saved. But my if msgbox isn't working.

Can anyone help my cause? Thx. Sarita

Private Sub Form_BeforeUpdate(Cancel As Integer)
If MsgBox("do you want to save?") ,vbYesNo = vbYes
Else
Cancel = True
MsgBox "Update was cancelled", vbOKOnly
End If
End Sub

Your If statement syntax is wrong. Try:

If MsgBox("do you want to save?", vbYesNo) = vbYes Then

Carl Rapson
 
G

Guest

Thank you guys! I feel like a dingbat right now. I kept bringing the Then
to the next line and it was giving me the error constraint. Now if my users
are entering a new record or editing one and they close the form their
changes don't save unless they want to. You guys were my second set of eyes.

It worked perfectly!!!!

Sarita
 

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