PDA

View Full Version : Solved: Trouble Accessing Active Mailitem



wnazzaro
04-30-2007, 10:00 AM
I want this code to check the size of an e-mail message before it sends and if the message is going to be 1MB or larger, alert the user and allow the send to be cancelled. The code below seems to work, as long as there is only one item in the collection ActiveExplorer.Selection. However if more than one message is open, the wrong message may be checked for size. I think all I need is the line of code that sets Item = Active MailItem, however I can't seem to locate the correct syntax. All help is greatly appreciated.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim YN As Byte
Set Item = ActiveExplorer.Selection(1)

If Item.Size > 999999 Then
YN = MsgBox("The message you want to send is " & _
CStr(Item.Size) & " bytes large. Are you certain" & _
" you want to send this message", vbYesNo, "Message Size")

If YN = 6 Then
Cancel = False
Else
Cancel = True
End If
End If
End Sub

geekgirlau
04-30-2007, 11:02 PM
Delete this line:


Set Item = ActiveExplorer.Selection(1)


The mail item is passed to this procedure by default, so it will automatically recognise the item being sent no matter how many mail items are currently open.

wnazzaro
05-01-2007, 07:03 AM
You would think that should work, but it doesn't. When I put MsgBox Item.Size as the first line of code, the box reads "0", regardless of the size of the message. It's not until I Set Item that the code works.

wnazzaro
05-01-2007, 10:29 AM
A-ha!

The mail item has a size of 0 until it is saved. I added Item.Save to my code and all works now. I got this information from OutlookCode.com (http://www.outlookcode.com) and Sue Mosher.