Outlook & VB Problem

I'm trying put in only one e-mail, the one with the matching subject and body. To do this i'm passing the function the subject and body and they are called pSubject and pBody.


    'Set mr = Inbox.Items.Restrict("[Subject] = '" & pSubject & "' AND [Body] = '" & pBody & "'")
   
    Set mr = Inbox.Items.Restrict("[Subject] = '" & pSubject & "'")

The commentted out line is the one i really ant to use but the second one is for testing and this one doesn't work.

It works IF the subject passed in pSubject contains no single quotes '
As soon as a single quote appears it dies.

What i'm looing for is, is there some way of escaping the ' here '" & pSubject & "'. I know in perl i would just simplely \' and it would work but i can't figure out a way of doing it here.

Cheers
g_landAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

g_landAuthor Commented:
anyone have any possible answers, i'd really stuck on this and can;t move on till i get this.

Cheers
0
Tommy KinardCommented:
Set mr = Inbox.Items.Restrict("[Subject] = '" & replace(pSubject,"'",vbnullstring) & "'")
If you are using VB6 the replace function will replace all occurances of the single quote with nothing.
0
g_landAuthor Commented:
i tried that but because it replaces the 1 with nothing it fails the search to find the subject!

Thanks for the suggestion
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

g_landAuthor Commented:
for future reference the answer is:

Set mr = Inbox.Items.Restrict("[Subject] = """ & pSubject & """")

George
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CleanupPingCommented:
g_land:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
DanRollinsCommented:
g_land, an EE Moderator will handle this for you.
Moderator, my recommended disposition is:

    Refund points and save as a 0-pt PAQ.

DanRollins -- EE database cleanup volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.