If statements that depend on multiple fields

  • Thread starter Thread starter StacyM
  • Start date Start date
S

StacyM

I am trying to code a text box to give results based on multiple inputs from
other fields. If the user selects corn for the field, the box would give
5000, if they select soybeans it would be 5000, or if the select milk it
would be 200000. But if the futures contract option is selected, the user
needs to be able to input their own number. There are other options in the
contract options, but they won't change the contract size. I am very close to
getting it in VBA code, but I am really new at this, so any help would be
appreciated. Thanks a bunch!
 
I am trying to code a text box to give results based on multiple inputs from
other fields. If the user selects corn for the field, the box would give
5000, if they select soybeans it would be 5000, or if the select milk it
would be 200000. But if the futures contract option is selected, the user
needs to be able to input their own number. There are other options in the
contract options, but they won't change the contract size. I am very close to
getting it in VBA code, but I am really new at this, so any help would be
appreciated. Thanks a bunch!

=IIf([FieldName]="Corn" Or [FieldName]="Soybean",5000, IIf([FieldName]
= "Milk",200000,InputBox("How much?"))

It might be better to create a function and use Select Case instead of
IIf.
You can also use the Switch Function.
Look them up in VBA help.
 
fredg said:
I am trying to code a text box to give results based on multiple inputs from
other fields. If the user selects corn for the field, the box would give
5000, if they select soybeans it would be 5000, or if the select milk it
would be 200000. But if the futures contract option is selected, the user
needs to be able to input their own number. There are other options in the
contract options, but they won't change the contract size. I am very close to
getting it in VBA code, but I am really new at this, so any help would be
appreciated. Thanks a bunch!

=IIf([FieldName]="Corn" Or [FieldName]="Soybean",5000, IIf([FieldName]
= "Milk",200000,InputBox("How much?"))

It might be better to create a function and use Select Case instead of
IIf.
You can also use the Switch Function.
Look them up in VBA help.
Thanks for your help, and after some trial and error, it worked well with a
fairly simple select case function. Thanks again.
 
Back
Top