Field validation - Displaying an error message?

R

Richard Horne

Hi,

I have a form with three fields :

Quantity, Quantity Delivered, Quantity Remaining.

The Quantity Remaining field = Quantity - Quantity Delivered

Can someone please tell me the code to validate this field so that if
Quantity Delivered > Quantity the error message "You have tried to enter a
quantity to deliver that is greater than the quantity ordered"

I have tried the code below which I don't think is too far off but it
doesn't work:

=IIf([Quantity Delivered]>[Quantity Ordered],"You are trying to send more
than was ordered!")
 
N

Niklas Östergren

Try this code in the control txtQuantityDelivered_LostFocus Event

' Code starts here
If Me.txtQuantityDelivered > Me.txtQuantity Then

MsgBox "You are trying to send more than was ordered!", vbQuestion +
vbOk, "Opps some text here"

End If
' Code ends here

This asumes that you have two controls on your form with name
txtQuantityDelivered and txtQuantity.

Another way of doing the same thing is like this:

' Code starts here
If Me.txtQuantity - Me.txtQuantityDelivered > 0 Then

MsgBox "You are trying to send more than was ordered!", vbQuestion +
vbOk, "Opps some text here"

End If
' Code ends here

// Niklas
 
R

Richard Horne

Hi Niklas I have tried your code - but it didn't seem to work. Could this be
because I have spaces in my field names?

Niklas Östergren said:
Try this code in the control txtQuantityDelivered_LostFocus Event

' Code starts here
If Me.txtQuantityDelivered > Me.txtQuantity Then

MsgBox "You are trying to send more than was ordered!", vbQuestion +
vbOk, "Opps some text here"

End If
' Code ends here

This asumes that you have two controls on your form with name
txtQuantityDelivered and txtQuantity.

Another way of doing the same thing is like this:

' Code starts here
If Me.txtQuantity - Me.txtQuantityDelivered > 0 Then

MsgBox "You are trying to send more than was ordered!", vbQuestion +
vbOk, "Opps some text here"

End If
' Code ends here

// Niklas

Richard Horne said:
Hi,

I have a form with three fields :

Quantity, Quantity Delivered, Quantity Remaining.

The Quantity Remaining field = Quantity - Quantity Delivered

Can someone please tell me the code to validate this field so that if
Quantity Delivered > Quantity the error message "You have tried to enter a
quantity to deliver that is greater than the quantity ordered"

I have tried the code below which I don't think is too far off but it
doesn't work:

=IIf([Quantity Delivered]>[Quantity Ordered],"You are trying to send more
than was ordered!")
 
R

Richard Horne

Oh wait, it works now! I just needed to put the msgbox code all on one line!

Niklas you're a star! Thanks mate.

Richard Horne said:
Hi Niklas I have tried your code - but it didn't seem to work. Could this be
because I have spaces in my field names?

Niklas Östergren said:
Try this code in the control txtQuantityDelivered_LostFocus Event

' Code starts here
If Me.txtQuantityDelivered > Me.txtQuantity Then

MsgBox "You are trying to send more than was ordered!", vbQuestion +
vbOk, "Opps some text here"

End If
' Code ends here

This asumes that you have two controls on your form with name
txtQuantityDelivered and txtQuantity.

Another way of doing the same thing is like this:

' Code starts here
If Me.txtQuantity - Me.txtQuantityDelivered > 0 Then

MsgBox "You are trying to send more than was ordered!", vbQuestion +
vbOk, "Opps some text here"

End If
' Code ends here

// Niklas

Richard Horne said:
Hi,

I have a form with three fields :

Quantity, Quantity Delivered, Quantity Remaining.

The Quantity Remaining field = Quantity - Quantity Delivered

Can someone please tell me the code to validate this field so that if
Quantity Delivered > Quantity the error message "You have tried to enter a
quantity to deliver that is greater than the quantity ordered"

I have tried the code below which I don't think is too far off but it
doesn't work:

=IIf([Quantity Delivered]>[Quantity Ordered],"You are trying to send more
than was ordered!")
 
N

Niklas Östergren

You are welcome!

I hope you understand that you should change the caption of the textbox to
something meaningfull!? ;-)

// Niklas

Richard Horne said:
Oh wait, it works now! I just needed to put the msgbox code all on one line!

Niklas you're a star! Thanks mate.

Richard Horne said:
Hi Niklas I have tried your code - but it didn't seem to work. Could this be
because I have spaces in my field names?

Niklas Östergren said:
Try this code in the control txtQuantityDelivered_LostFocus Event

' Code starts here
If Me.txtQuantityDelivered > Me.txtQuantity Then

MsgBox "You are trying to send more than was ordered!", vbQuestion +
vbOk, "Opps some text here"

End If
' Code ends here

This asumes that you have two controls on your form with name
txtQuantityDelivered and txtQuantity.

Another way of doing the same thing is like this:

' Code starts here
If Me.txtQuantity - Me.txtQuantityDelivered > 0 Then

MsgBox "You are trying to send more than was ordered!", vbQuestion +
vbOk, "Opps some text here"

End If
' Code ends here

// Niklas

"Richard Horne" <[email protected]> skrev i meddelandet
Hi,

I have a form with three fields :

Quantity, Quantity Delivered, Quantity Remaining.

The Quantity Remaining field = Quantity - Quantity Delivered

Can someone please tell me the code to validate this field so that if
Quantity Delivered > Quantity the error message "You have tried to enter a
quantity to deliver that is greater than the quantity ordered"

I have tried the code below which I don't think is too far off but it
doesn't work:

=IIf([Quantity Delivered]>[Quantity Ordered],"You are trying to send more
than was ordered!")
 
S

StCyrM

Good afternoon

You were so close. Check out the IIF statement in Help. You were missing the
False side of the equation


=IIf([Quantity Delivered]>[Quantity Ordered],"You are trying to send more
than was ordered!"," ")


Best regards

Maurice St-Cyr

Hi,

I have a form with three fields :

Quantity, Quantity Delivered, Quantity Remaining.

The Quantity Remaining field = Quantity - Quantity Delivered

Can someone please tell me the code to validate this field so that if
Quantity Delivered > Quantity the error message "You have tried to enter a
quantity to deliver that is greater than the quantity ordered"

I have tried the code below which I don't think is too far off but it
doesn't work:

=IIf([Quantity Delivered]>[Quantity Ordered],"You are trying to send more
than was ordered!")
 
Top