Prevent user from saving a record in if statement

dealwi8me

Registered User.
Local time
Today, 13:51
Joined
Jan 5, 2005
Messages
187
Hello,

Code:
If <if clause> then
' can't save record
end if

How can i prevent the user from saving the record when <if clause> is true?
I'm using a continious form and i want to prevent save only in those records that <if clause> is true.

Thank you in advance.
 
Put your code in the "Before" X events of your form. Set Cancel to true if your "if clause" is true:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Cancel = MyIfClause 'You might want to tell the user that they can't update here.
End Sub

is an example of "cancelling" an update. You'd need similar logic if you were cancelling an Insert or Delete operation.
 
thank you for answering!

What value should i assing in cancel if if clause is true?

if <clause> then
msgbox("You are not allowed to save the record.")
cancel= ???
end if
 
thank you for answering!

What value should i assing in cancel if if clause is true?

if <clause> then
msgbox("You are not allowed to save the record.")
cancel= ???
end if

The normal way is Cancel = True
 
You can also assign Cancel to any formula that calculates as true or false. You are allowed to use boolean operators (i.e. "Not" can reverse the value of your calculation).
 

Users who are viewing this thread

Back
Top Bottom