AutoEmailing Reports

S

SZito

I have a function that runs at Startup and if at a certain time it is supposed to send an email. It has worked fine until this week. All of the sudden I get Error 2046 "OutputTo not available". The thing is that it still runs fine on an older version of the database, but there haven't been any chages the code itself or the reports its supposed to output. Any suggestions would be greatly appreciated, here is the code I am using:

Option Compare Database
Option Explicit
______________________________
Public Function EmailFollowUp()

Dim StartTime As String
Dim olapp As Outlook.Application
Dim olmail As Outlook.MailItem
Dim strto As String
Dim strSubject As String
Dim strattach As String
Dim strrptName As String
Dim strrptfile As String


StartTime = "11:35 PM"

If WeekDay(Now(), vbMonday) < 5 Then
If Format(Now(), "Medium time") = Format(StartTime, "Medium time") Then
Dim olapp As Outlook.Application
Dim olmail As Outlook.MailItem
Dim strto As String
Dim strSubject As String
Dim strattach As String
Dim strrptName As String
Dim strrptfile As String

strrptName = "rptFollowUp"
strrptfile = "F:\Databases\snpReports\rptFollowUp.snp"
strto = "steve.zito@seagatetravel"
strSubject = "Customer Service Follow Up Report"
strattach = strrptfile

DoCmd.OutputTo acOutputReport, strrptName, _
acFormatSNP, strrptfile, False

Set olapp = CreateObject("Outlook.Application")
Set olmail = olapp.CreateItem(olMailItem)

olmail.To = strto
olmail.Subject = strSubject
olmail.Attachments.Add (strattach)
olmail.Send

DoCmd.Quit acQuitSaveAll
Else
DoCmd.OpenForm "frmCSDATA"
End If
ElseIf WeekDay(Now(), vbMonday) = 5 Then
If Format(Now(), "Medium time") = Format(StartTime, "Medium time") Then
strrptName = "rptFollowUpfri"
strrptfile = "F:\Databases\snpReports\rptFollowUp.snp"
strto = "(e-mail address removed)"
strSubject = "Customer Service Follow Up Report"
strattach = strrptfile

DoCmd.OutputTo acOutputReport, strrptName, _
acFormatSNP, strrptfile, False

Set olapp = CreateObject("Outlook.Application")
Set olmail = olapp.CreateItem(olMailItem)

olmail.To = strto
olmail.Subject = strSubject
olmail.Attachments.Add (strattach)
olmail.Send

DoCmd.Quit acQuitSaveAll
Else
DoCmd.OpenForm "frmCSDATA"
End If
Else
DoCmd.OpenForm "frmCSDATA"
End If
End Function
 
D

Dirk Goldgar

SZito said:
I have a function that runs at Startup and if at a certain time it is
supposed to send an email. It has worked fine until this week. All
of the sudden I get Error 2046 "OutputTo not available". The thing
is that it still runs fine on an older version of the database, but
there haven't been any chages the code itself or the reports its
supposed to output. Any suggestions would be greatly appreciated,
here is the code I am using:

Option Compare Database
Option Explicit
______________________________
Public Function EmailFollowUp()

Dim StartTime As String
Dim olapp As Outlook.Application
Dim olmail As Outlook.MailItem
Dim strto As String
Dim strSubject As String
Dim strattach As String
Dim strrptName As String
Dim strrptfile As String


StartTime = "11:35 PM"

If WeekDay(Now(), vbMonday) < 5 Then
If Format(Now(), "Medium time") = Format(StartTime, "Medium
time") Then Dim olapp As Outlook.Application
Dim olmail As Outlook.MailItem
Dim strto As String
Dim strSubject As String
Dim strattach As String
Dim strrptName As String
Dim strrptfile As String

strrptName = "rptFollowUp"
strrptfile = "F:\Databases\snpReports\rptFollowUp.snp"
strto = "steve.zito@seagatetravel"
strSubject = "Customer Service Follow Up Report"
strattach = strrptfile

DoCmd.OutputTo acOutputReport, strrptName, _
acFormatSNP, strrptfile, False

Set olapp = CreateObject("Outlook.Application")
Set olmail = olapp.CreateItem(olMailItem)

olmail.To = strto
olmail.Subject = strSubject
olmail.Attachments.Add (strattach)
olmail.Send

DoCmd.Quit acQuitSaveAll
Else
DoCmd.OpenForm "frmCSDATA"
End If
ElseIf WeekDay(Now(), vbMonday) = 5 Then
If Format(Now(), "Medium time") = Format(StartTime, "Medium
time") Then strrptName = "rptFollowUpfri"
strrptfile = "F:\Databases\snpReports\rptFollowUp.snp"
strto = "(e-mail address removed)"
strSubject = "Customer Service Follow Up Report"
strattach = strrptfile

DoCmd.OutputTo acOutputReport, strrptName, _
acFormatSNP, strrptfile, False

Set olapp = CreateObject("Outlook.Application")
Set olmail = olapp.CreateItem(olMailItem)

olmail.To = strto
olmail.Subject = strSubject
olmail.Attachments.Add (strattach)
olmail.Send

DoCmd.Quit acQuitSaveAll
Else
DoCmd.OpenForm "frmCSDATA"
End If
Else
DoCmd.OpenForm "frmCSDATA"
End If
End Function

Steve -

When you say "it still runs fine on an older version of the database",
what sort of change to the "version of the database" are you referring
to? Is it the database itself that you have modified, or your version
of Access, or what? I've seen some problems with the snapshot format
constant not being defined in, I think Access 2003, but I'll have to
research it to be sure. Suppose you change from acFormatSNP to
acFormatTXT (or XL), and change the file name appropriately, does it
work then?
 
S

SZito

Apparently it was the fact that the Database window was hidden, That was the only real difference between the different versions (sorry, versions of the database, not Access) Once I changed the start-up options of the newer version so that the database window appears, the code runs fine...It works for now I can still hide the window in the distributed .mdbs since the only one that runs at a scheduled time in on my system. I'm not sure why that window has to be open though, and would like to find a way to be able to keep it hidden and still have the fnuction run correctly..
 
D

Dirk Goldgar

SZito said:
Apparently it was the fact that the Database window was hidden, That
was the only real difference between the different versions (sorry,
versions of the database, not Access) Once I changed the start-up
options of the newer version so that the database window appears, the
code runs fine...It works for now I can still hide the window in the
distributed .mdbs since the only one that runs at a scheduled time in
on my system. I'm not sure why that window has to be open though, and
would like to find a way to be able to keep it hidden and still have
the fnuction run correctly..

Interesting. I hadn't encountered this before, but it does seem that
the database window must be visible in order to use the OutputTo method.
A somewhat unsatisfactory workaround could be to show the database
window temporarily, output the report, then hide the database window
again:

DoCmd.SelectObject acReport, "MyReport", True

DoCmd.OutputTo acOutputReport, "MyReport", _
acformatSNP, "C:\Temp\MyReport.snp"

Application.RunCommand acCmdWindowHide
 
S

SZito

Yeah, I was thinking about that too, I'm glad you put the code in because that would have been my next question. Thanks for all you help
 
K

Kevin Witty

To quote a neighbor's girl: OMiGod!

I've just converted to 2003 and had been getting the "outputto not
available", and would never in a thousand years had guessed that it had
anything to do with the database window being open, or that "
DoCmd.SelectObject acReport, "MyReport", True" would have opened it, or that
"Application.RunCommand acCmdWindowHide" was the right syntax to close it!
Maybe my new subscription to MSDN Professional will pay off after all!

On a slightly different topic, which I couldn't even frame a subject for,
I've also noticed that some things, as yet undefined, cause the database
window to scroll VERY RAPIDLY from top to bottom everytime SOMETHING (as yet
undefined) happens. Any idea what's causing this?

Kevin
 

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