Help with Access VB Function

G

Guest

I need help with conditional formatting in an Access Report. How the
information needs to displays is based on the data in four fields. I have
tried writing a VB function within Access for this; however, I cannot get
past a Null Value error.
The fields are PrimaryFirst, PrimaryLast, SecondaryFirst, SecondaryLast
If SecondaryFirst AND SecondaryLast are Null (no data) than
Name=PrimaryFirst + PrimaryLast
IF PrimaryLast AND SecondaryLast are EQUAL than
Name = PrimaryFirst + “and†+ SecondaryFirst + PrimaryLast
IF PrimaryLast AND SecondaryLast are NOT EQUAL than
Name=PrimaryFirst+PrimaryLast+â€andâ€+SecondaryFirst+SecondaryLast

It is possible that the SecondaryFirst and SecondaryLast fields will be
empty, it is even a remote possibility that the PrimaryFirst field is empty.

Your help is greatly appreciated!
 
J

John Spencer

It would have helped if you posted your function. GUESSES follow
-- have you declared your four arguments as Variant (those are the only
types that can accept nulls)

Your Function should look something like this. You need to work out the
logic for what you want to do for the various combinations of Nulls and
matches

Public Function GetName (PFirst as Variant, PLast as Variant, _
SFirst as Variant, SLast as
Variant) as Variant

IF IsNull(SFirst) and IsNull(SLast) And IsNull(PFirst) = False and
IsNull(PLast) = False Then
GetName = PFirst & " " & PLast
ELSEIF ... Then

ELSEIF ... Then
...
End If

End Function
 

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

Top