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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


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

Independent Software Vendors: 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!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

777 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