Pick the larger of 2 text fields

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

Guest

I want to create a text field which is the larger of 2 existing text fields.
If I try to use the IIf function to compare the Len() of each field the
result can not be the larger text field. It appears that the IIf function
value must be some form of a number. My exact need can be expressed this way
- Assume you have 2 Text Fields A and B and that the text field C is the
result of the following: If B is not null then C = B else C = A. This
should be very simple but the the fact that these are all text fields is
causing problems. Any help would be appreciated,
 
First write a function (aircode):

Public Function Foo(A As String, B As String) As String
On Error Resume Next
If Len(A & vbNullString) > Len(B & vbNullString) Then
Foo = A
Else
Foo = B
End Function

Now use it in a query column:

C: Foo([Field A], [Field B])
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top