Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation on amount

Status
Not open for further replies.

djeeten

Programmer
Mar 13, 2003
59
BE
Hi,

I have this field 'Amount' on a subform 'sfrmOrders'. Every time a product is choosen (from a listbox on the main form) it is inserted in the subform and the 'Amount' is set to 1.

Now, whenever the 'Amount' of a certain product is changed on the subform, the total cost of the order (Sum(amount*price)) is changed as well immediately (as I requery whenever an amount is changed).

Private Sub Amount_Change()
Me.Requery
End Sub

Now, I would like to have a validation on the field were the amount has to be filled in. It should be > 0 and it should also be a number.

I tried to put the validation on the field 'Amount' in the table, but then I get an error on the Requery event.

Then I tried this:

Private Sub Amount_Change()
If (Me!Amount < 1) Then
MsgBox &quot;The amount has to be more than 0!&quot;
Me.Undo
Me!Amount = 1
Me.Requery
Else
Me.Requery
End If
End Sub

This works, but somehow it only works for the first line on the subform?

Could someone please give me some advice?

Thanks in advance,

dj.
 
I 'm very sorry, this was a stupid question. ;) I only had to put the validation code in the before_update event of the 'Amount' field.

However, how can I make sure only numbers can be entered in the textbox where the amount has to be filled in?

dj.

 
See my post in thread68-501559. It may be what you are looking for.

 
Thanks Zathras, but I found a much nicer solution:


Private Sub Amount_KeyPress(KeyAscii As Integer)
If ((KeyAscii < 48) Or (KeyAscii > 57)) Then
KeyAscii = 0
End If
End Sub


That's all I needed ;-)

dj.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top