PDA

View Full Version : add to subject with a form



cdgraham
05-06-2010, 09:59 AM
I'm new to VBA and this is a basic problem I'm sure. I want to change the subject if an @ symbol is the first character. I have a list of items you can add, "ACTION", "INFO", etc. or "" (nothing). So if the subject is "@ meeting" a popup form comes up and I select option ACTION the subject becomes "ACTION meeting". Here is my code for the form and session.

ThisOutlookSession:
'handle the Send event for the mail item
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If Item.Subject = "@" Then
SubjectType.Show vbModal 'see if the user wants to add a Subject
End If
End Sub

Private Sub m_UserForm_DataReady(ByVal sSubject As String)
'we get the Subject from the form, passed by the raised form event.
'we get this event before m_oMail_Send finishes so any Subject we add
' gets added to the mail item before it goes out.
Item.Subject = sSubject & Item.Subject
End Sub

SubjectType form:
Public Event DataReady(ByVal sSubject As String)
Dim strSubject As String

Private Sub cmdOK_Click()
RaiseDataReadyEvent 'fire DataReady event
Unload Me
End Sub

Private Sub optAction_Click()
strSubject = "ACTION "
End Sub

Private Sub optCoord_Click()
strSubject = "COORD "
End Sub

Private Sub optInfo_Click()
strSubject = "INFO "
End Sub

Private Sub optNoPrefix_Click()
strSubject = ""
End Sub

Private Sub RaiseDataReadyEvent()
'this event is handled externally to the form
'it passes the new subject text
RaiseEvent DataReady(strSubject)
End Sub

I know there are a couple of things I haven't done, replacing or check @. But I can't seem to add the option text to the subject. Also, how do I change it to get rid of the OK button, just click the radio button and send the prefix text back?