If, then condition in a form

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

Guest

I have a form with a drop down list box we will called Field A that is
populated with various text items. I would like to have
another field, Field B, that will display a number when one of the text
items in
Field A is selected, sort of an if, then type condition. The numbers will be
assigned to the worded items in the list
box from Field A accordingly by me. Is this possible? Thanks for the help!
 
In Field A, the field with the list box I would have for example apple,
orange, and bannana as the text to choose from. In field B, I would like it
to display a 1 if the user chose apple, a 2 if the user chose orange, etc..
Does this help?
 
Todd,

There are a couple of ways you can do that.

1. Using a Select Case block. This is the recommended option:
Select Case Me![Field A]
Case "apple"
Me![Field B] = 1
Case "orange"
Me![Field B] = 2
Case "banana"
Me![Field B] = 3
End Select

2. Using the Switch function:
Me![Field B] = Switch(Me![Field A] = "apple", 1, _
Me![Field A] = "orange", 2, _
Me![Field A] = "banana", 3)

You should put this code in Field A's AfterUpdate event.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
 
Todd,

In addition to Graham's solution, I think you may wish to consider putting
your text values and their associated numbers in a Table. They are more
visible and easily edited there, and you don't need any code to assign the
numeric value to a textbox.

Have your combo box get its rows from the table, and include the key field,
the description, and the associated number. You can limit the drop-down
display to the description alone by setting the 1st and 3rd columns width to
0" in the Column Width property.

Assign the numeric value associated with the user's pick to your textbox by
setting its Control Source property to:

= YourComboBox.Column(2)

HTH
Sprinks
 
Back
Top