In the past I've set up scheduled reports to be sent out as emal attachments using the Windows task scheduler to fire up Access and used a command line switch to start a macro. The macro would run a query that the sendobject was based on and then do a sendobject.
I'd like to do something a little different. I'd like to send out an individual scheduled report to each of the companines in a table. The table would have company name, account number and the email address to send the report.
I'm sort of putting together some code and am not sure of the syntax etc.
I plan on doing the scheduling and the command line to fire up a macro which will first open the table of company names and email addresses then run the following code:
Function exportreport()
Dim stTo As String, ststartDate As String, stendDate As String, stcc As String, stconame As String
Dim stMessage As String
Dim dbs As DAO.Database
Dim rst As DAO.RecordSet
Set dbs = CurrentDb
Set rst = dbs.OpenRecordSet("reportaccounts ")
While Not rst.EOF and Not rst.BOF
stTo = Me![tables]![reportaccounts]!
ststartDate = Date()-90
stendDate = Date()
stconame = [Tables]![reportaccounts]![coname]
DoCmd.SendObject acSendQuery, "export qry", acFormatXLS, [stTo], , , [stconame] & " " & "Quarterly Reports" & " " & ststartDate & " " & "to" & " " & stendDate, “This is your quarterly report”, False
rst.MoveNext
Wend
Am I on the right track? Also, I need to get the account number into the query. Do I use Me![tables]![reportaccounts]![accountnumber] ??
Thanks in advance
I'd like to do something a little different. I'd like to send out an individual scheduled report to each of the companines in a table. The table would have company name, account number and the email address to send the report.
I'm sort of putting together some code and am not sure of the syntax etc.
I plan on doing the scheduling and the command line to fire up a macro which will first open the table of company names and email addresses then run the following code:
Function exportreport()
Dim stTo As String, ststartDate As String, stendDate As String, stcc As String, stconame As String
Dim stMessage As String
Dim dbs As DAO.Database
Dim rst As DAO.RecordSet
Set dbs = CurrentDb
Set rst = dbs.OpenRecordSet("reportaccounts ")
While Not rst.EOF and Not rst.BOF
stTo = Me![tables]![reportaccounts]!
ststartDate = Date()-90
stendDate = Date()
stconame = [Tables]![reportaccounts]![coname]
DoCmd.SendObject acSendQuery, "export qry", acFormatXLS, [stTo], , , [stconame] & " " & "Quarterly Reports" & " " & ststartDate & " " & "to" & " " & stendDate, “This is your quarterly report”, False
rst.MoveNext
Wend
Am I on the right track? Also, I need to get the account number into the query. Do I use Me![tables]![reportaccounts]![accountnumber] ??
Thanks in advance