How do I Replace a string with a variable?

C

Carol G

I am trying to set the item using a variable strFullName
the variable value is "Cherif Abdallah" with the quotes included but If I
substitute the variable in the place of the name in the set item. I get an
error.

Thanks
Carol

***Everything declared here***

Dim strFullName As String

strFullName = "Cherif Abdallah"
strFullName = """" & strFullName & """"
Debug.Print strFullName

Set itm = fld.Items.Find("[FullName] = ""Cherif Abdallah""") 'This works
but I want to replace it with a variable.
 
S

Sue Mosher [MVP-Outlook]

strFind = "[FullName] = " & Chr(34) & strFullName & Chr(34)
Set itm = fld.Items.Find(strFind)

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
C

Carol G

I think I also have a valid string but when I use it (or your version below)
I get a run time error saying.
Condition is not valid and a long number. Highlighting at my Set itm code.

Here is all my code. Any ideas? I have this code in a module in Access
2000. Just to test it.
Thanks Carol

Private Sub test()

Dim fld As Outlook.MAPIFolder
Dim appOutlook As Outlook.Application
Dim nms As Outlook.NameSpace
Dim itms As Outlook.Items
Dim itm As Outlook.ContactItem


Set appOutlook = CreateObject("Outlook.Application")
Set nms = appOutlook.GetNamespace("MAPI")
Set fld = nms.GetDefaultFolder(olFolderContacts) 'Set what kind of folder
Set itms = fld.Items 'Outlook folder item

Dim strFullName As String
strFullName = "Cherif Abdallah"
strFind = "[FullName] = " & Chr(34) & strFullName & Chr(34)


'strFullName = """" & "[FullName] = " & strFullName & """"
Debug.Print strFullName

Set itm = fld.Items.Find(strFullName)
'Debug.Print itm.LastName
'

End Sub



strFind = "[FullName] = " & Chr(34) & strFullName & Chr(34)
Set itm = fld.Items.Find(strFind)
 
S

Sue Mosher [MVP-Outlook]

The easy way to find out what you're doing wrong is to check the actual value of the variable you're using in your Set itm statement. I think you'll see the problem immediately and then kick yourself. (Hint: Compare my response with your code.)
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
C

Carol G

Extra quotes. found them but it took a while.
Thanks Carol
The easy way to find out what you're doing wrong is to check the actual
value of the variable you're using in your Set itm statement. I think you'll
see the problem immediately and then kick yourself. (Hint: Compare my
response with your code.)
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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