VB code in Access Query....

Status
Not open for further replies.

ringo1079

Ars Praefectus
3,421
Subscriptor
Hello Everyone!

We're working with three fields: FirstName,MiddleName, and LastName

We're trying to get the following output:

If the value in FirstName is null, then we would like to simply give us the value of LastName and be finished.

If the value of FirstName is NOT null then we would like test the MiddleName field. If the MiddleName field is NOT null then give us that value in the query, as well as the LastName value.

So there can be 3 combinations:

LastName
FirstName, LastName
FirstName, MiddleName, LastName

Here is the code we've constructed thus far, which does work...however it is giving us a leading "half character" position before the value that is in the field, but only when there is a value in FirstName. So it turns out like this:

LastName
FirstName, LastName
FirstName, MiddleName, LastName

Our code attempts:

expr4: IIf([FirstName] Is Null,[LastName],IIf([MiddleName] Is Null,[LastName],[FirstName] & " " & [MiddleName] & " " & [LastName]))

expr5: IIf([FirstName] Is Null,[LastName],[FirstName] & IIf([MiddleName] Is Null,""," " & [MiddleName])) & [LastName]

if ANYONE can shed ANY light on this...it would be GREATLY appreciated.

TIA,
CJK
 

ringo1079

Ars Praefectus
3,421
Subscriptor
OK...the Forum didnt show my leading half character position in the post
Here is the code we've constructed thus far, which does work...however it is giving us a leading "half character" position before the value that is in the field, but only when there is a value in FirstName. So it turns out like this:

LastName
FirstName, LastName
FirstName, MiddleName, LastName

But there is one...just so you guys dont think im crazy :)
 

ringo1079

Ars Praefectus
3,421
Subscriptor
well...haha i dont know, half the length of a normal character position...depending on a few diff adjustments we get either a full leading character position or a half position.

Thanks for the SQL...i'll give it a whirl... :D

ehh i just tried the SQL in Access...and its telling me that i need to enclose the statement in brackets, and after i did that, Access told me i was using a reserved expression (i think it said "expression")

hmm...thanks...it was worth a shot :)
 
Status
Not open for further replies.