Problem sending mail from Access

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
 
R

Rick Brandt

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,"")
 
S

SF

It works! Thank you.

SF

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top