Sending mail from access form button

  • Thread starter Mitch via AccessMonster.com
  • Start date
M

Mitch via AccessMonster.com

The following is what I am trying to use to email more than 1 person (in the
"To" field). It actually works, but now I want to use a variable from the
form, in my case it would be "me.emailaddy", but when I use that i get
"invalid use of null". I know it is because I don't use quotes, but I can't
with a variable in there... what am I overlooking?

---------------------------

Private Sub Mail_Click()


Dim strTo As String
Dim strSubject As String
Dim strMsg As String
strTo = "(e-mail address removed);[email protected]"
strSubject = "MY SUBJECT"
strMsg = "MY MSG"

DoCmd.SendObject acSendNoObject, , acFormatTXT, strTo, , , strSubject, "",
True
 
J

james.igoe

I don't know that it is possible. Someone I worked with tried to use
the DoCMD.SendObject, and I could not find a way to help, so I created
a function to do the work. Call the function from another module,
passing it the string of addresses as a variable, along with attachment
and subject:


Function fxSendOutlookEmail(strAttachme­ntName As String,
strRecipients
As
String, strSubject As String) As Boolean


Dim objOutlookApp As New Outlook.Application
Dim objOutlookMail As Outlook.MailItem
Dim objOutlookAttachments As Outlook.Attachments


Set objOutlookApp = CreateObject("Outlook.Applicat­ion")
Set objOutlookMail = objOutlookApp.CreateItem(olMai­lItem)


With objOutlookMail
.To = strRecipients
.Subject = strSubject
.Body = vbCrLf & vbCrLf & strAttachmentName & vbCrLf & vbCrLf
.Attachments.Add strAttachmentName, olByValue, 500
.Send
End With


fxSendOutlookEmail = True


Exit Function


'releases resources from outlook and associated components
If Not objOutlookApp Is Nothing Then


objOutlookApp.Quit


If Not objOutlookMail Is Nothing Then
Set objOutlookMail = Nothing
End If


If Not objOutlookAttachments Is Nothing Then
Set objOutlookAttachments = Nothing
End If


Set objOutlookApp = Nothing


End If


fxSendOutlookEmail = False


End Function
 
S

Steve Schapel

Mitch,

Do you mean you are putting like this?...
strTo = Me.emailaddy

As far as I can see, the most likely cause of the problem is that there
is no data in the emailaddy control on the form at the time you are
trying to run the code. Would this be right?
 
M

\Mitch via AccessMonster.com\

In reply to Steve,
no, on my form there really is no way to have the me.emailaddy blank. The
only reason to even to fill out the form is to assign someone this dispatch
call, which I would like to go to their email "emailaddy" and there cell
phone "vmailaddy"... does that make sense?

Also I want to add other things to the body of the email automaticlly (phone
number from another table). I hope that makes sense... thanks for the help.
 
M

\Mitch via AccessMonster.com\

I apologize for not being clear... I really need two variables to be in the
strTo field
 
S

Steve Schapel

Mitch,

No apology needed, I think you have been clear enough about what you
want. However, as I understand it, there is an 'invalid use of null'
error resulting from what you have done,... but you haven't said what
you have done, so it's pretty hard to track down. Maybe you could post
the code that is causing the error?
 

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

Similar Threads

Email Issue 2
Task Scheduler 3
stop code sending cancelled email 11
dao recordset error 3
Email Body Blank 1
Run query from different database 2
Email from Access 1
Email endless loop 4

Top