Re: How to use an IFF statement for validation rule

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Wow, Allen, that's great. It works nicely. Actually, I have two columns, one
for inventory 'IN' and one for inventory 'OUT'. So, I added on to the rule to
take care of the OUT column, too, following the example you gave.

I also tried this on the text boxes in the form and it also works. Thanks a
bunch. It was simpler than I thought. No need for an If-Then statement.

"Allen Browne" wrote:

1. Open the table in design view.

2. Open the Properties box (View menu.)

3. Beside the Validation Rule in the Properties box, enter something like
this:
([TransType] = 1 AND [In] = 0) OR ([TransType] = 2 AND [In] > 0)

Replace TransType with the name of the field that the combo is bound to.

Notes:
====
a) Since you are comparing fields, you must use the rule in the properties
box, not the one in the lower pane of table design (which is the rule for a
field.)

b) The bracketing is important when mixing ANDs and ORs.

c) Using IN as a field name could cause you problems, since it is a reserved
word in JET SQL. Here's a list you can refer to when designing tables:
Problem names and reserved words
at:
http://allenbrowne.com/AppIssueBadWord.html

d) Your IN field is for a quantity. You might want to consider whether there
could be cases where a sale is for a quantity also.

e) If the sale quantity must always be zero, the TransType might be
superflous (i.e. IN = 0 could be the indicator for a sale.)

f) If you do have a Quantity field that is used for both purchases and
sales, you might use -1 = Sale and 1 = Purchase. This would allow you to sum
the expression:
SaleType * Quantity
for the net difference for each product.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"PAULinLAOS" <PAULinLAOS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:405D541D-C740-4F49-B359-8225B9396A2B@xxxxxxxxxxxxxxxx
I want to validate data entry in one control based on another. It's an
inventory database. In one control, I choose from a combo box called
[Combo18] whether the record is a 'Sale' or a 'Purchase'.
'Sale'/'Purchase'
is stored in the control [type] as a number, Sale=1 and Purchase=2. I also
have one field/control for [IN], which is a number/amount for how many
items
were purchased. So, the rule is that if the combo box shows 'Purchase',
then
[IN] should be an integer of 1 or more. If it's a sale, then [IN] is zero.

I've tried, unsuccessfully, at writing a validation rule in the properties
of the [IN] text box on the form as follows:

IIf([type]=2,>0,0)

I also tried:

IIf(Forms![inventory]![Combo18]="Purchase",>0,0)

Neither of these work. Any idea of how to write this simple IF/THEN
statement to validate my data entry?



.



Relevant Pages

  • Re: validate data in form based on another control
    ... After the type of sale is entered, e.g. sale, purchase, gift, ... inventory IN must equal zero and the inventory OUT must be greater than zero. ... The validation rule is simply there to ensure that the user doesn't enter ...
    (microsoft.public.access.forms)
  • Re: sales journal and inventory management
    ... A typical business day involves the sale of 3 or 4 inventory items ... Purchases of replacement inventory ...
    (microsoft.public.excel.misc)
  • Re: ADO: Deleting a table after it is loaded into Recordset
    ... I have an inventory management ... The Purchases table lists all the inventory purchased day to day. ... Same way the Sales portion works. ... inventory register of a particular barcode. ...
    (microsoft.public.vb.general.discussion)
  • Re: Excel to track inventory?
    ... sales (out of inventory) and purchases. ... track Sales Qty using this formula in E2 ...
    (microsoft.public.excel)
  • Re: NETWORK INVENTORY
    ... Given you want an accurate inventory at the time of each sale and you don't ... Your Resource For Help With Access, Excel And Word Applications ... It turns out we were short quanity for customer. ...
    (comp.databases.ms-access)