mail attachment

adil_karampurwa

Registered User.
Local time
Yesterday, 23:11
Joined
Sep 18, 2006
Messages
23
Hi all
I have a form "frmSendEmail" having buttons "attachment" and "send mail"
on click of attachemnt a file can be attached,
on click of send mail mail can be sent.
but if nothing is attached mail cant be send it shows an error "invalid use of null" i want mail to be send with out attachments
code for "send mai"l is
Private Sub cmdSend_Click()
On Error GoTo Whoops
If txtTo <> "" And txtSubject <> "" And txtBody <> "" Then
Dim objOL As Outlook.Application, msg As MailItem, objAttch As Object
Dim strAttachment As String, strarray() As String, intReturn As Integer, x As Integer
Set objOL = CreateObject("Outlook.Application")
Set msg = objOL.CreateItem(olMailItem)
strAttachment = txtAttachment
With msg
.To = txtTo
If Not IsNull(txtCC) Then .CC = txtCC
.Subject = txtSubject
.Body = txtBody
If Not IsNull(strAttachment) Then
Set objAttch = .Attachments
intReturn = SplitVB5(strAttachment, "; ", strarray)
For x = 1 To intReturn
objAttch.Add Trim(strarray(x)), , 5000
Next
End If
If chkDisplay Then
.Display
Else: .Send: MsgBox " Message sent!"
End If
End With
txtTo = Null
txtCC = Null
txtSubject = Null
txtBody = Null
chkDisplay = False
txtAttachment = Null
txtAttachment.Visible = False
lblAttachment.Visible = False
cmdAttachment.Caption = "Add Attachment"
Else: MsgBox " All fields are required."
End If
OffRamp:
On Error Resume Next
Set objOL = Nothing
Exit Sub
Whoops:
MsgBox "Error #" & ": " & Err.Description
Resume OffRamp
End Sub

and for "atachment" is
Dim intReturn As Integer
Dim strarray() As String
Dim strNewAttachment As String

strNewAttachment = ahtCommonFileOpenSave(, "C:\", , , "pdf", , "Select file to attach")
If Nz(strNewAttachment) = "" Then Exit Sub 'No attachment specified

If Nz(Me.txtAttachment) = "" Then
Me.txtAttachment = strNewAttachment
Else
Me.txtAttachment = Me.txtAttachment & "; " & strNewAttachment
End If

intReturn = SplitVB5(txtAttachment, "/", strarray)
strDisplayName = strarray(intReturn)
intReturn = SplitVB5(strDisplayName, ".", strarray)
strDisplayName = strarray(2)
txtAttachment.Visible = True
lblAttachment.Visible = True
cmdAttachment.Caption = "Add Another"

plz help
Thanxx
 

Users who are viewing this thread

Back
Top Bottom