Auto fill a combo box if criteria met

  • Thread starter Thread starter Eric Graham
  • Start date Start date
E

Eric Graham

Is there a way to have a combo box fill in either yes or no depending on
what information is put into another field? For instance if this field says
N/A this combo box says yes, if same field says any thing other that N/A the
combo box says no. Any help would be appreciated.

TIA
Eric
 
Why a combo box, if it is to be filled in automatically? Why not a text box?
Another suggestion of how to proceed: In the text box for the Yes or No
field, put something like:
=IIf([FirstField] = "N/A","Yes","No")
or
=IIf([FirstField]="","",IIf([FirstField] = "N/A","Yes","No"))
The second choice should keep the field blank until there is a value in the
first field. You could also use the default value as suggested in the other
post. Depends on the details of your situation.
 
I am having a time trying to figure out where to put the code below.


Bruce said:
Why a combo box, if it is to be filled in automatically? Why not a text box?
Another suggestion of how to proceed: In the text box for the Yes or No
field, put something like:
=IIf([FirstField] = "N/A","Yes","No")
or
=IIf([FirstField]="","",IIf([FirstField] = "N/A","Yes","No"))
The second choice should keep the field blank until there is a value in the
first field. You could also use the default value as suggested in the other
post. Depends on the details of your situation.

Eric Graham said:
Is there a way to have a combo box fill in either yes or no depending on
what information is put into another field? For instance if this field says
N/A this combo box says yes, if same field says any thing other that N/A the
combo box says no. Any help would be appreciated.

TIA
Eric
 
My suggestion was for an unbound text box on a form. If you want to store
the "Yes" or "No" you could proceed as follows. The code supposes that the
field that could contain the "N/A" value is named FirstField, the field
containing "Yes" or "No" is named YN, the text box bound to the YN field is
named txtYN, and the combo box bound to FirstField is cboFirstField. The
following code is in the Exit event for cboFirstField. It could be in After
Update or some other event, depending on your needs.

If Me.FirstField = "N/A" Then
Me.YN = "Yes"
Else: Me.YN = "No"
End If

Me.txtYN.Requery

Although you haven't specified, I am assuming you have a form based on the
table or query containing the fields described in this post. To insert the
code, open the form in design view. Double click cboFirstField. Click the
Event tab, then the On Exit row. Click the three dots at the right side,
click Code Builder, then click OK. Insert the code from this post at the
blinking cursor (between Private Sub... and End Sub) in the code window,
changing the names to match your field and control names.

Eric Graham said:
I am having a time trying to figure out where to put the code below.


Bruce said:
Why a combo box, if it is to be filled in automatically? Why not a text box?
Another suggestion of how to proceed: In the text box for the Yes or No
field, put something like:
=IIf([FirstField] = "N/A","Yes","No")
or
=IIf([FirstField]="","",IIf([FirstField] = "N/A","Yes","No"))
The second choice should keep the field blank until there is a value in the
first field. You could also use the default value as suggested in the other
post. Depends on the details of your situation.

Eric Graham said:
Is there a way to have a combo box fill in either yes or no depending on
what information is put into another field? For instance if this field says
N/A this combo box says yes, if same field says any thing other that N/A the
combo box says no. Any help would be appreciated.

TIA
Eric
 
Back
Top