PDA

View Full Version : Does this line of code do anything?



sharon ann
09-24-2007, 11:22 AM
Hi

The following code was found at SearchExchange.com and was coded apparently by Sue Mosher MVP. It forces an Outlook user to fill in the subject line before sending an Email.

This is the code - it works with or without the line "Dim lngRes As Long" - to be honest I'm not sure what that line of code is doing there...

Private Sub Application_ItemSend _
(ByVal Item As Object, Cancel As Boolean)
Dim strMessage As String
Dim lngRes As Long
if Item.Subject = "" Then
Cancel = True
strMessage = "Please fill in the subject before sending."
MsgBox strMessage, _
vbExclamtion + vbSystemModal, "Missing Subject"
Item.Display
End if
End sub

Can anyone enlighten me - is it a mistake, does it mean something or is it doing something.

Thanks

(ps I will post the http address later on in case anyone is interested).

Norie
09-24-2007, 11:30 AM
Well it is doing something - declaring lngRes as a long variable.

But it isn't used anywhere else in the code so I don't think it's needed.:)

sharon ann
09-24-2007, 12:08 PM
Unfortunately the forum won't allow me to post the http address.

Norie
09-24-2007, 12:51 PM
sharon

I don't see why you need to post the link.

Like I said that line of code is doing something but what it's doing isn't used anywhere else in the code you've posted.

Brandtrock
09-25-2007, 12:53 AM
As Norie has pointed out, this line isn't necessary for the specific routine that you posted.

When searching Google for the first line of the routine you posted, I found these two documents at the site you mentioned. The lngRes variable is used in the first routine and appears to simply have been a left over in the second. Removing it from the second routine shouldn't cause any difficulty for you.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim lngRes As Long
If InStr(1, UCase(Item.Body), "ATTACH") <> 0 Then
If Item.Attachments.Count = 0 Then
lngRes = MsgBox("'Attach' in body, but no attachment - send anyway?", _
vbYesNo + vbDefaultButton2 + vbQuestion, "You asked me to warn you...")
If lngRes = vbNo Then Cancel = True
End If
End If
End Sub



Private Sub Application_ItemSending _
(ByVal Item As Object, Cancel As Boolean)
Dim strMessage As String
Dim lngRes As Long
If Item.Subject = "" Then
Cancel = True
strMessage = "Please fill in the subject before sending."
MsgBox strMessage, _
vbExclamation + vbSystemModal, "Missing Subject"
Item.Display
End If
End Sub

Regards,