Expression in Field to display 1 of 2 data entries

  • Thread starter Thread starter Ryan
  • Start date Start date
R

Ryan

Fairly new to access programming trying to get a field to
display the same data is entered in another field but
also to choose a different fields data to display if the
second field has something entered into it. If this
makes sense can somebody help me?

Ryan
 
Ryan said:
Fairly new to access programming trying to get a field to
display the same data is entered in another field but
also to choose a different fields data to display if the
second field has something entered into it. If this
makes sense can somebody help me?

I think you're asking for a control source expression in a
text box like:

=IIf(IsNull(secondfield), firstfield, secondfield)

But that would not be editable. If you are trying to set a
control's value that could be changed, then you could use
code:

If IsNull(Me.secondfield) Then
Me.textbox = Me.firstfield
Else
Me.textbox = Me.secondfield
End If

But you didn't explain enough for me to know where you're
going to put that code.
 
I have field1 which data is entered into..I then have
field2 which can have data entered sometimes...I have
another field3 which must display either field1 or field2
data. What I want to do is if field1 has data display
that data in field3....if field1 and field2 both have
data I need field3 to display the field2 data. I hope
this makes more sense. I don't want to alter the tables
because they are linked and that would promote a lot of
other changes that would have to be made.

Ryan
 
Building on the post by Marsh, if you are using a single
form, set the control source for field3 to

=IIf(IsNull(secondfield), firstfield, secondfield)


If you are using Datasheet view or Continuous Forms view,
you will need to work a little harder to display what you
want.

(If the control source for the form is a table, stop,
create a query for the form, then continue.)

If the control source for the form is a query, then in
design view of the query, add this line

OneOrTwo:IIf(IsNull(secondfield),firstfield,secondfield)

to the Field line (top line) in an empty column of the
query grid. Change the field names to your names.

In design view of the form, set the control source for
Field3 control to the field OneOrTwo (or whatever you
decide to call it).

HTH

Steve
 
Back
Top