Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   Outlook Vb, Check Address if address BlaBla then send else run script (http://www.go4expert.com/forums/outlook-vb-check-address-address-blabla-t25191/)

sauko 8Mar2011 21:29

Outlook Vb, Check Address if address BlaBla then send else run script
 
Hi,

What I want to do is the following. I want the script to search the adress field, if the one you want to send to is @gmail.com, SEDABO (a group with contacts which all use the domain @hotmail.com) or two other internal address group(not global address). IF the script finds one of these it should just go ahead and send the email even though it found C1,C2 or C3 in the subject.

If the subject is C1,C2 or C3 and the email is supposed to be sent to lets say Robin@Batcave.com it should run the script with the warning.

This is what I have so far, dont know how to finish it.

What is done so far:
+I the warning signs work
+You can cancel the email if you press no when the warning appears
+ It checks the address for a string, But only one string, and if it finds it, it runs the script instead of just sending the email.
Code:

 
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim strTo As String

strTo = Item.To
If InStr(1, strTo, "@gmail.com", vbTextCompare) > 0 Then

Dim strSubject As String
strSubject = Item.Subject
 
If InStr(1, strSubject, "C1", vbTextCompare) > 0 Then
Prompt$ = "Are you sure you want to send C1?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True

End If
End If

If InStr(1, strSubject, "C2", vbTextCompare) > 0 Then
Prompt$ = "Are you sure you want to send C2?"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
 
End If
End If
 
If InStr(1, strSubject, "C3", vbTextCompare) > 0 Then
Prompt$ = "Are you sure you want to send C3"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
Cancel = True
 
End If
End If

End If

End Sub

Thank you for all your help,

Kind Regards
Daniel


All times are GMT +5.5. The time now is 12:19.