Search for semicolon in a string!

  • Thread starter Thread starter Niklas Östergren
  • Start date Start date
N

Niklas Östergren

Hi!

Is there a function in Access 2003 which I can use to search for a sign (ex.
semicolon)?

I´m about to create a code modul for sending e-mails using Microsoft Outlook
and one of the parameters that one procedure will get from the procedure
that calls this <CreateOlEmailMsg> is a string of path to one or several
files to be attached to this mail msg. This is, offcource, optional so the
user can choose if to attache files or not.

I havné done this before so if there might be a better way pleas let me
know. This is what I´m thinking of right now:

The variable (strAttmentsPath) will get a string like this:

strAttmentsPath = "C:\report.txt ; C:\BcBtRmv.log"

What I´d like to do is to seperate these path so I could add attachement so
I´d get this result:

.Attachments.Add "C:\report.txt"
.Attachments.Add "C:\BcBtRmv.log"
The thing that I have never done and don´t know how to solve here is to
seperate string strAttmentsPath?

Any help is apprechiated!

TIA!
// Niklas
 
Niklas,

Access built-in function InStr() returns the position of a string (in
your case a single character) within another - look it up in help. So,

pos = InStr(1, strAttmentsPath, ";")

will set the value of pos to 15 in your example. Then you can use this
in with right / left / mid functions, possibly together with the len
function, to get what you want.

HTH,
Nikos
 
Actually, even better in this case would be the Split function: it'll
convert that string into an array of values, each corresponding to a
specific entry.

Dim intLoop As Integer
Dim varValues As Variant

varValues = Split(strAttachmentPath, ";")
If IsNull(varValues) = False Then
For intLoop = LBound(varValues) To UBound(varValues)
.Attachments.Add varValues(intLoop)
Next intLoop
Else
' Nothing in strAttachmentPath
End If
 
Thank´s a lot Douglas!

Split-function was exactly what I wanted, but I didn´t know that it was
there.

I had to change your example a little since the array is zero-based:

For intLoop = LBound(varValues) To UBound(varValues) - 1

But exept for that it worked like a train.

You know what! During this week I have learnt about arrays. I have read
about them many times but have never been able to se where and when to use
them. But this week everything have fallen into the right place :-). I also
have discovered how to use <CreateItem> together with MS Outlook. So I fell
quit sattisfyed for this week :-)

Thank´s for helping me out with this!

// Niklas
 
Hi Nikos!

Thanks for helping me out, even if I din´t go for your solution.
I fell for the built in Split-function which Douglas mention about.

Thank´s for taking time anyway!

// Niklas
 
Niklas Östergren said:
Thank´s a lot Douglas!

Split-function was exactly what I wanted, but I didn´t know that it
was there.

I had to change your example a little since the array is zero-based:

For intLoop = LBound(varValues) To UBound(varValues) - 1

But exept for that it worked like a train.

I think your modification to Doug's code is in error. Using LBound and
UBound, it shouldn't matter whether the array is zero-based or not.

Given ...

Dim arrMyArray(9) ' 10 elements, numbered 0 to 9

Then

LBound(arrMyArray) ----> 0
UBound(arrMyArray) ----> 9
 
Well maby, I havn´t used array´s for so long time, as you might know. But
without -1 I got an error saying that the path was incorrect and that the
file couldn´t be found. So I added "'" to the code and used Debug.Print to
see what happened, like this:

Debug.Print "'" & varValues(intLoop) & "'"

This gave following result:
'C:/FileName1.ext'
'C:/FileName2.ext'
''

So I changed the code to:
For intLoop = LBound(varValues) To UBound(varValues) - 1

Which gave me this:
'C:/FileName1.ext'
'C:/FileName2.ext'

I tested the code and an e-mail was created with the attached files localy
stored on my pc. So it seams to work.

You mean that I might get some other problem with this that I may not have
discovered yet?

// Niklas
 
Well maby, I havn´t used array´s for so long time, as you might know. But
without -1 I got an error saying that the path was incorrect and that the
file couldn´t be found. So I added "'" to the code and used Debug.Print to
see what happened, like this:

Debug.Print "'" & varValues(intLoop) & "'"

This gave following result:
'C:/FileName1.ext'
'C:/FileName2.ext'
''

this is from your Split, it means that the last position was a ";"

a split gives you every time a LBound of 0 therefore you can write:
For intLoop =0 To UBound(varValues)
' now check if the the result is right
' there could be also two ";" in the string
if varValues(intLoop)<>"" then
'do your code
endif
next intLoop


If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
 
Hi Andi!

This was the case so I changes the code again and didn´t add any attachement
if varValues(intLoop) = "".

Thank´s a lot for helping out!

// Niklas
 

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

Back
Top