Problem sending mail from Access

  • Thread starter Thread starter SF
  • Start date Start date
S

SF

Hi,

I have a form for user to send mail. There are several fields in the form
such as txtTo, txtCC, txtBCC, txtSubject etc.

I am experience a problem when one the following field is blank.

Private Sub cmdSend_Click()
DoCmd.Hourglass True
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem

Set olApp = New Outlook.Application
Set olMsg = CreateItem(olMailItem)
With olMsg
.To = Me.txtTo
.CC = Me.txtCC >> Error when blank
.BCC = Me.txtBcc >> Error when blank
.Subject = Me.txtSubject
.Body = Me.txtBody
.Send
End With
DoCmd.Hourglass False

TIA

SF
 
SF said:
Hi,

I have a form for user to send mail. There are several fields in the
form such as txtTo, txtCC, txtBCC, txtSubject etc.

I am experience a problem when one the following field is blank.

Private Sub cmdSend_Click()
DoCmd.Hourglass True
Dim olApp As Outlook.Application
Dim olMsg As Outlook.MailItem

Set olApp = New Outlook.Application
Set olMsg = CreateItem(olMailItem)
With olMsg
.To = Me.txtTo
.CC = Me.txtCC >> Error when blank
.BCC = Me.txtBcc >> Error when blank
.Subject = Me.txtSubject
.Body = Me.txtBody
.Send
End With
DoCmd.Hourglass False

Likely those are strings properties and cannot be set to Null. Try wrapping them
in Nz() like...

..CC = Nz(Me.txtCC,"")
 
Back
Top