A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How do I Replace a string with a variable?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 2nd 06, 01:08 AM posted to microsoft.public.outlook.program_vba
Carol G
external usenet poster
 
Posts: 25
Default How do I Replace a string with a variable?

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.


  #2  
Old December 2nd 06, 02:16 AM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How do I Replace a string with a variable?

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

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Carol G" wrote in message news:Kt3ch.403350$5R2.166903@pd7urf3no...
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.


  #3  
Old December 2nd 06, 04:08 AM posted to microsoft.public.outlook.program_vba
Carol G
external usenet poster
 
Posts: 25
Default How do I Replace a string with a variable?

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



"Sue Mosher [MVP-Outlook]" wrote in message
...
strFind = "[FullName] = " & Chr(34) & strFullName & Chr(34)
Set itm = fld.Items.Find(strFind)


  #4  
Old December 2nd 06, 02:17 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How do I Replace a string with a variable?

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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Carol G" wrote in message news:I66ch.408324$R63.290451@pd7urf1no...
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



"Sue Mosher [MVP-Outlook]" wrote in message
...
strFind = "[FullName] = " & Chr(34) & strFullName & Chr(34)
Set itm = fld.Items.Find(strFind)


  #5  
Old December 2nd 06, 05:24 PM posted to microsoft.public.outlook.program_vba
Carol G
external usenet poster
 
Posts: 25
Default How do I Replace a string with a variable?

Extra quotes. found them but it took a while.
Thanks Carol
"Sue Mosher [MVP-Outlook]" wrote in message
...
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Carol G" wrote in message
news:I66ch.408324$R63.290451@pd7urf1no...
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



"Sue Mosher [MVP-Outlook]" wrote in message
...
strFind = "[FullName] = " & Chr(34) & strFullName & Chr(34)
Set itm = fld.Items.Find(strFind)




 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing variable to the To field Matthew Brewer Outlook and VBA 1 June 9th 06 06:38 AM
Variable Date Meetings Susan Vega Outlook - Calandaring 1 March 22nd 06 05:58 PM
Outlook Application variable problem Ram Add-ins for Outlook 0 February 12th 06 03:25 PM
Variable attachment and recipient vb Xluser@work Outlook and VBA 1 January 21st 06 10:05 AM
string variable that contains formatting Martin Outlook and VBA 4 January 19th 06 10:49 AM


All times are GMT +1. The time now is 07:07 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.