The script below will work if I take out the remarks, name it as a Sub Routine instead of a function. However, I want to send it data and recieve a response. When I convert it to a Function (or event leave it as a Sub Routing I get a Name Redefined Error. I know you need to pass the varialble to VB Script in "" when using VBEval, however I have tried it both ways.
The purpose of the script it to see if a Contact in Outlook already exists. I want to return 0 if no greater than 0 if yes.
Code: Select all
VBSTART
Function FindContact (strInput)
Dim objOutlook
Dim objNameSpace
Dim objFolder
Dim strInput
'Dim strMsg
Dim cItem
Dim strOutput
Dim counter
Const olFolderContacts = 10
Const cTextCaseInsensitive = 1
' strMsg = "Enter a search string." & vbcrlf & "(Example: Dan)"
' strInput = InputBox(strMsg,"Search For ...","Dan")
'strInput = "wertert"
Set objOutlook = CreateObject("Outlook.application")
Set objNameSpace = objOutlook.GetNameSpace("MAPI")
Set objFolder = objNameSpace.GetDefaultFolder(olFolderContacts)
counter = 0
For Each cItem in objFolder.Items
If Instr(1,cItem.FullName,strInput,cTextCaseInsensitive) > 0 Then
counter=counter+1
strOutput = String(45,"~") & vbCrLf
strOutput = strOutput & "Full Name:" & vbTab & cItem.FullName & vbCrLf
strOutput = strOutput & strAddress & vbCrLf
strOutput = strOutput & String(45,"~") & vbCrLf & counter
' Msgbox strOutput, , cItem.Subject
End If
Next
If strOutput = "" Then
'Msgbox "No contacts match search requirements."& vbCrLf & counter, vbInformation,"Contact Search"
End If
' **** Clean up
'
Set objFolder = Nothing
Set objNameSpace = Nothing
set objOutlook = Nothing
END Function
VBEND
VBEval>FindContact("John"),answer
MDL>%answer%
Any idea as to where I am going wrong?