I want a field to save with 0.00

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I get a field to save only when that particular field becomes 0.00.
The field is based off a query where it is the balance. I want an error to
occur when it doesn't equal 0.00 and prompt the user to get the equation
down to 0.00. How can this be done???
 
It's on a form and its is bound. I could enter an equation in the query that
it is linked to, but how exactly do I do that? Any advice is greatly
appreciated.
 
Not it the query. In this case it would do no good. FYI avoid equations in
queries unless absolutely necesssary, it slows them way down. I would try
putting your check in the Before Update event of the text box for the field.
Here is the concept (air code)

If Me.txtMyText <> 0 Then
if msgbox("Gotta Have Zero", vbOkCancel.... ) = vbOkCancel Then
Cancel = True
Else
Do what you need to do to get to zero
endif
end if
 
Just a quick correction, the part after the equal sign should be vbCancel,
not vbOkCancel.

Doing this in the BeforeUpdate of the textbox will do this as the value in
the textbox changes. What are you doing to make this value change? If it is
through code, the BeforeUpdate event doesn't fire when the value is changed
through code. You can either call the BeforeUpdate event yourself in the
code that caused the change or do the value check yourself in the code that
caused the change (preferable). You could also use the BeforeUpdate event of
the form. This will make the check as the user tries to save the record and
will cancel the save if you choose to cancel.
 
Thanks, Wayne - I was in a bit of a hurry there.

Wayne Morgan said:
Just a quick correction, the part after the equal sign should be vbCancel,
not vbOkCancel.

Doing this in the BeforeUpdate of the textbox will do this as the value in
the textbox changes. What are you doing to make this value change? If it is
through code, the BeforeUpdate event doesn't fire when the value is changed
through code. You can either call the BeforeUpdate event yourself in the
code that caused the change or do the value check yourself in the code that
caused the change (preferable). You could also use the BeforeUpdate event of
the form. This will make the check as the user tries to save the record and
will cancel the save if you choose to cancel.
 
Back
Top