How to reference draft email where there are forms?

Viewed 250

The user creates an email then clicks on the Send button, and a form will appear and there are options to send.
One option is to send an email and the recipient will receive the message on their mobile phone. When he selects this option, another form will appear to enter the mobile number and confirm with the button on the form to submit.

The problem is receiving the current draft e-mail message Set objMail = Application.ActiveInspector.CurrentItem generates an error message

Object variable or With block variable not set

Without forms the code works.

1] first form is called from ThisOutlookSession

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    FormSending.Show
End Sub

Code of ButtonSend and Call main function from module SendWithSms

Private Sub ButtonSend_Click()
    Dim intDelta As Integer

    Call SendWithSms
    
    blnContinue = True
    Unload Me
End Sub

2] second form is in form folder and is called from function SendWithSms

'....
    User_form.Show
        
    If blnContinue = False Then
        Exit Sub
    End If

    .Send
End With
'....

Is possible to identify the email message to be sent where there are forms?

2 Answers

solution:

to ThisOutlookSession add this part of code

Public objMail As Outlook.mailItem

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
      Dim objMail As Outlook.mailItem
      Dim CurrentItem As Object
    
      Set objMail = Application.ActiveInspector.CurrentItem

      FormSending.Show

End Sub

You can define the Show method in your custom form with a parameter which can deliver an instatnce of the Outlook item for which the form is displayed, so you could pass it instantly:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
   If TypeName(Item) = "MailItem" Then
     FormSending.Show Item
   End If
End Sub
Related