dbTalk Databases Forums  

Use function in query - Left / Mid / InStr

comp.databases.ms-access comp.databases.ms-access


Discuss Use function in query - Left / Mid / InStr in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Sabine Newsgroup Access
 
Posts: n/a

Default 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

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.