before update

S

scott04

Hi everyone. I am using the following code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.Combo60 = True And (Nz(Me.Personal_Data_Inaccuracies, 0)) +
(Nz(Me.Improper_Combine, 0)) = 0 Then
MsgBox "You selected yes to the Maintenance Issue question, therefore
please select the number of errors in that section", vbCritical
Cancel = False ' Stop the process
End If
End Sub
If you try and save it prompts for the msgbox one time. How can i make it
so that the message comes up until they enter the required data or change the
field to false? Thanks.
 
B

BruceM

Cancel = False has the effect of telling Access to ignore the line of code
and go ahead with the update. Cancel = True, on the other hand, will cancel
the update (that is, the save won't happen). Try something like:
Cancel = True
Me.Combo60.SetFocus
 
S

scott04

Bruce,
I tried what you suggested and it still allows me to save without going back
to asking for the code again.
 
B

BruceM

What do you mean by "save without going back to ask for the code again"?
Are you saying that if the user clicks the Save button again the record will
be saved with no prompt for additional fields?
On another point, if "True" for Combo60 is a text value it needs to be in
quotes.
 
S

scott04

Bruce,
Sorry for not responding sooner. The when you hit my command button to save
or exit, the code runs and the message box pops up as it should. If you hit
ok to the msgbox and then hit save again it allows you to save the
information.
 
B

BruceM

I have done some testing, and cannot duplicate the problem. Your code
should be something like:
If Me.Combo60 = True And _
(Nz(Me.Personal_Data_Inaccuracies, 0)) + _
(Nz(Me.Improper_Combine, 0)) = 0 Then
MsgBox "You selected yes to the Maintenance Issue question,
therefore " & _
"please select the number of errors in that section", vbCritical
Cancel = True
End If

By the way, you may need to trap the error that occurs in the comman button
code when you cannot save the record.

Before you attempt to save a new or changed record, the record's "Dirty"
property is True. If you cancel the update, the record is not saved; its
"Dirty" property is still True. If you try again to save the record, the
same thing should occur as when you first tried to save the record. What is
the exact code you are using in Before Update?
 

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