Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email with attachment not sending

Status
Not open for further replies.

snyperx3

Programmer
May 31, 2005
467
US
here is my current code:
Code:
Private Sub cmdExportFile_Click()
    If DCount("TicketNum", "qryExport", "Prefix='000'") < 1 Then
        Call MsgBox("There are no new work orders to export.", vbOKOnly)
        Exit Sub
    End If
    If MsgBox("Are you sure you want to export and e-mail the new work orders?", vbYesNo, "Export and Email?") Then
        DoCmd.TransferText acExportDelim, , "qryExport", "G:\ServiceTech\Exports\EXPORT" & Format(Date, "yyyymmdd") & "_" & Format(Time(), "hhmm") & ".csv"
        DoCmd.SetWarnings False
        DoCmd.OpenQuery "qrySetAsExported", acViewNormal
        DoCmd.SetWarnings True
        
        Dim appOutlook As Object
        Set appOutlook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutlook.CreateItem(0)

        With MailOutLook
            'replaced to protect
            .Recipients.Add ("***@***.***")
            .Subject = "New Work Orders.  Exported " & Format(Date, "yyyymmdd") & "_" & Format(Time(), "hhmm")
            .Body = "These are the new work orders that were entered on the office side of the Service Tech System."
            .Attachments.Add "G:\ServiceTech\Exports\EXPORT" & Format(Date, "yyyymmdd") & "_" & Format(Time(), "hhmm") & ".csv"
            .Send
        End With
    End If
End Sub

When I run this code on my machine, and there are work orders to be exported it opens the outlook warning windows and everything (which is fine), i say yes to all of them, but it never actually sends the message.

When I run this on a test environment (using Access runtime), it gives me the error "The expression On Click you entered as the event property setting produced the following error: The operation on the | object failed."

Does anyone know what's causing the email not to send on my end, or why it fails to even attempt on the runtime end?

Thanks for any help.

-Pete
 
Try:

Code:
<...>
        With mailoutlook
            'replaced to protect
            .To = ("***@***.***")
            .Subject = "New Work Orders.  Exported " & Format(Date, "yyyymmdd") & "_" & Format(Time(), "hhmm")
            .Body = "These are the new work orders that were entered on the office side of the Service Tech System."
            .Attachments.Add "G:\ServiceTech\Exports\EXPORT" & Format(Date, "yyyymmdd") & "_" & Format(Time(), "hhmm") & ".csv"
            .Display
        End With
    End If
    Set mailoutlook = Nothing
    Set appOutlook = Nothing
 
Thanks for your reply Remou.

When I tried exactly as you posted it gave a runtime error on .To = ("***@***.***")

I removed the parenthesis and tried again. This time it didnt crash, but it did the same as before: showed the outlook warning, acted like it sent the mail, but the mail was never actually sent. I'm testing it by sending it to myself, and I'm never getting my test mail.

Any other ideas?

-Pete
 
Alright, I've found one of my problems.

I was under the impression that the object would work with outlook or outlook express. I didn't have an email setup on outlook...only outlook express.

Once i opened Outlook i saw 15 emails sitting in the outbox waiting to be sent. I set up an account in outlook and was able to send the old ones out.

I have a new problem though: Now that the program is sending them to outlook...why arent they leaving the outbox? When the warning shows I am clicking yes, so it should automatically send them right?

-Pete
 
Have you tried creating and sending an email without any automation?
 
yes and it worked fine.

I have tested this on the test environment (using Access runtime), and strangely it successfully sent the email, but froze Access immediately afterwards.

-Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top