Avatar billede dennisa Nybegynder
15. april 2008 - 15:16 Der er 8 kommentarer og
1 løsning

Send flere rapporter med DoCmd.SendObject acReport

Kan man det ?
Avatar billede mugs Novice
15. april 2008 - 15:20 #1
Det mener jeg ikke.

Men du kan jo lave en rapport med tilhørende underrapporter og sende den.
Avatar billede dennisa Nybegynder
15. april 2008 - 15:24 #2
Sorry, den dur ikke. Brugeren vælger selv hvilke rapporter der skal videresendes i vilkårlig rækkefølge.

DoCmd.SendObject er jo også en "gammel" metode / levn fra fortiden. Findes der ikke nogle nyere metoder ?
Avatar billede terry Ekspert
15. april 2008 - 15:34 #3
Try using DoCmd.OutputTo in a loop for all of your reports and then send your mail using Outlook where you attach the files
Avatar billede dennisa Nybegynder
15. april 2008 - 15:39 #4
Hi terry

Any chance of you having an example ?
Avatar billede terry Ekspert
15. april 2008 - 15:57 #5
maybe later when I get home from work, but here is a link which sends a query to a file where the file name is taken form a table.

You need to alter the code a little so that it takes the name of the report from a table and maybe also the corresponding filename.
So you need a table which holds the reports name and file name. Then once you have this modify the code found in the link under user BAT17.


http://www.access-programmers.co.uk/forums/archive/index.php/t-96677.html   


Once you have got that working you then need to automate Outlook and then you will need to loop the table again to get the field names you need to attach. You sghould be able to find a number of questions here on eksperten concerning Outlook.


But I'll take a look later.
Avatar billede dennisa Nybegynder
15. april 2008 - 16:07 #6
Thanks
Avatar billede terry Ekspert
15. april 2008 - 18:55 #7
In the following example you need a reference to Outlook and DAO. And if you look at the code you'll see what table/field you need.

The name of the report in the table is also used as the file name but you could have another field if the file name is to be different.

In the Outlook code I have only added two attachments, you could alter this to loop through the table to attach all entries in the table.

Sub ReportsToFiles()
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
Dim strSql As String
Dim strPath As String

    strPath = "C:\TEMP\"
    strSql = "SELECT DISTINCT [ReportName] FROM tblReports"
   
    Set qdf = CurrentDb.CreateQueryDef("", strSql)
    Set rs = qdf.OpenRecordset
   
    Do While Not rs.EOF
        strCriteria = rs![ReportName]
       
        DoCmd.OutputTo acOutputReport, strCriteria, acFormatRTF, strPath & strCriteria & ".rtf"
       
        rs.MoveNext
    Loop
   
   
    Set rs = Nothing
    Set qdf = Nothing

    SendMail
   
End Sub

Function SendMail()
Dim objOl As New Outlook.Application
Dim objPost As MailItem
Dim vedhæftet As Attachments
   
    Set objPost = objOl.CreateItem(olMailItem)
   
    Set vedhæftet = objPost.Attachments
    vedhæftet.Add "C:\TEMP\rpt1.rtf"
    vedhæftet.Add "C:\TEMP\rpt2.rtf"
   
    With objPost
        .Subject = "Subject goes here"
        .To = "eksperten@santhell.dk"
        .Body = "Hej Med dig!"
       
        .Display
       
    End With
 
  objOl.Quit
 
    Set objPost = Nothing
    Set vedhæftet = Nothing
   
Exit Function

errhandler:
   
    MsgBox "ERROR: " & Err.Number & " - " & Err.Description

End Function
Avatar billede dennisa Nybegynder
16. april 2008 - 11:26 #8
Hi Terry

Works perfectly
Avatar billede terry Ekspert
16. april 2008 - 12:18 #9
great, and thanks
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester