Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Outlook & VB Problem

Posted on 2003-03-12
Medium Priority
Last Modified: 2010-04-07
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.

Question by:g_land

Author Comment

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

LVL 14

Expert Comment

by:Tommy Kinard
ID: 8139124
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.

Author Comment

ID: 8142326
i tried that but because it replaces the 1 with nothing it fails the search to find the subject!

Thanks for the suggestion
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

g_land earned 0 total points
ID: 8142942
for future reference the answer is:

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


Expert Comment

ID: 9056388
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 
Post your closing recommendations!  No comment means you don't care.
LVL 49

Expert Comment

ID: 9664565
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question