Use function in query - Left / Mid / InStr -
11-24-2011
, 06:54 AM
Hi there,
I need your experts' help again.
I have set up a query in such a way that it reads out the first letter
of a firstname to get its initials. You need to know that German
firstnames can be set up like this: "Hans-Peter". The results of my
query is "H.-P." which is absolutely correct.
However, I now want to format the same fields in the query through a
function. It properly works with the following:
The original content of the field in the query was:
-> PersonFirstName: IIf(IsNull([FirstName]);Null;Left([Firstname];1) &
".")
Now it reads:
-> PersonFirstName:
IIf(IsNull([FirstName]);Null;MyFormatFirstName([Firstname]))
And the function reads:
Function MyFormatFirstName(strfield As String) As String
MyFormatFirstName = Left(strfield, 1) & "."
End Function
As mentioned, all works well with the above ... The results of the
above in view of the name "Hans-Peter" is "H.".
However, now I still need the "-P." which I get through the
following.
PersonSecondName:IIf([FirstName] Like "*-
*";Left(Mid([FirstName];InStr([FirstName];"-"));2) & ".";Null)
If possible, I would now like to also use a function for the ->
Left(Mid([FirstName];InStr([FirstName];"-"));2) & "."
But I have to admit that I am lost! I was wondering whether anyone of
the experts here have a solution for me.
This would be great. Thanks!
Sabine |