Split Function

W

wpshop

I am trying to pull the following out "wkaupert" of this string. Can you
split by multiple delimiters? UserName = "CN=Wanita Kaupert/O=ABCD"

Below is the part of the code that refers to my dilemma. So far I have been
able to get to wkaupert/O. I know the Right reference is wrong but I can't
think of how to fix this and my brain is now fried.

UserName = Session.UserName
WordArray = Split(UserName, "=", -1, vbBinaryCompare)
MailDbName = Left$(WordArray(1), 1) & Right$(UserName, (Len(UserName) -
InStr(1, UserName, " "))) & ".nsf"
 
D

Daniel Pineault

There are many ways to do what you need, below is one.

'---------------------------------------------------------------------------------------
' Procedure : GetMailDbName
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' UserName - "CN=Wanita Kaupert/O=ABCD"
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
'
**************************************************************************************
' 1 2008-Dec-09 Initial Release
'---------------------------------------------------------------------------------------
Function GetMailDbName(UserName As String) As String
On Error GoTo Error_Handler
Dim iEqualPos As Integer
Dim iBackSlashPos As Integer
Dim ArrUserName As Variant

iEqualPos = InStr(1, UserName, "=")
UserName = Right(UserName, Len(UserName) - iEqualPos)

iBackSlashPos = InStr(1, UserName, "/")
UserName = Left(UserName, iBackSlashPos - 1)
ArrUserName = Split(UserName, " ")
GetMailDbName = LCase(Left(ArrUserName(0), 1) & ArrUserName(1) & ".nsf")

If Err.Number = 0 Then Exit Function

Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: GetMailDbName" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Function

End Function


You simply call it like:

GetMailDbName("CN=Wanita Kaupert/O=ABCD") and it will return 'wkaupert.nsf'
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
A

Albert D. Kallal

try:

UserName = "CN=Wanita Kaupert/O=ABCD"

strT = split(username,"=")(1)
strT = split(strT,"/")(0)

strT will now have your string of Wanita Kaupert
 
W

wpshop

Thank you both for taking the time to respond. I am working with the split
function listed below but I actually need to return wkaupert instead of
Wanita Kaupert. I am playing with it now but I'm new to this so I don't know
that I can figure this out.
 
W

wpshop

I figured it out! Thank you!

wpshop said:
Thank you both for taking the time to respond. I am working with the split
function listed below but I actually need to return wkaupert instead of
Wanita Kaupert. I am playing with it now but I'm new to this so I don't know
that I can figure this out.
 
G

Graham Mandeno

Sorry I didn't manage to follow up on your repost yesterday in the other
thread.

Daniel and Albert have given you two good methods for parsing the username
string, but I feel there must be a better way to ascertain the mailbox name
than by parsing the full name of the user.

For example, what happens if you have a username string like:
"CN=Andrew Lloyd Webber/O=ABCD"

And then, what happens if you have both
"CN=Wanita Kaupert/O=ABCD"
and
"CN=William Kaupert/O=ABCD"

First you need to find out the definitive rule for constructing the mailbox
name.

Is it this?

MailboxName = <login username>.nsp

If so, you'd be better to use some code that gives you the login username.
You will find a function that does that here:
http://www.mvps.org/access/api/api0008.htm
 

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