Ask Experts Questions for FREE Help !
Ask
    SoyJet's Avatar
    SoyJet Posts: 2, Reputation: 1
    New Member
     
    #1

    Mar 8, 2011, 08:39 AM
    Ms access automation email reports
    Scott, You've helped me before through All Experts. Please help me now, I'm at wits end

    Need help with automating the sending of access reports at night.

    I have several BAT files that run DISCOVERER exports to excel
    I have a VBS that loops through all those exports to re-save in a compliant version
    I have a VBS that runs several access subs to update the tables with the downloaded data
    Finally, and here's where it goes awry
    I have a VBS that runs a sub to OUTPUT a report, looping filter by slsman...
    All these are bundled in a BAT so they run one after the other
    This is inside a WS to make it run in the background, under Task Scheduler, at night..

    In the VBS MIDNIGHT REPORTING, I include the Resume and Suspend for Express Click Yes.

    It works fine, except that once the first report is open and ready to send, it bombs there.. it won't pass to Outlook, maybe because it has been idle?? \

    In the VBS that calls this report sub, trying to overcome this, I included some code to open and display the inbox, but it didn't work, either..

    Here's the vbs code, followed by the access function code:

    Code:
    option explicit
    
    On Error resume Next
    
    dim objFSO
    dim objFile
    Dim Log
    
    dim accObj
    DIM MyDb
    dim MyArray
    dim MyModule
    Dim item
    
    
    'added this outlook section to check if this would wake it up.  if it doesn't delete this outlook section thru
    ' where it sais error logging
    
    Dim oOutlook
    Dim oItems
    Dim oFirst
    
    
    '   Wake Outlook up from Idle
    
     Set oOutlook = GetObject("Outlook.Application")
     Set oItems = oOutlook.GetNameSpace("MAPI").GetDefaultFolder(6).Items.GetFirst()
     Set oFirst = oItems.GetFirst()
     oFirst.Display
     oFirst.Close
    
    Set oFirst = Nothing
    Set oItems = Nothing
    Set oOutlook = Nothing
    
    
    
    '   Error logging
    
    Const ForAppending = 8
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Log = "C:\home\Network Development\Regional Assistants\BackEnds\DiscvrRepSched\reporting.log"
    
    
    '   Open Access database
    Const ERR_APP_NOTRUNNING = 429
    
    MyDb = "C:\home\Network Development\Regional Assistants\Daily Task Management.mdb"
    
       Set accObj = GetObject(MyDb, "Access.Application")
    '   If Access isn't running, create a new instance.
       If Err = ERR_APP_NOTRUNNING Then
         Set accObj= New Access.Application
    	accObj.OpenCurrentDataBase MyDb
       End If
    
    
    
    ' ******** CHANGE TO CREATE DOUBLE ARRAYS FOR PATHS AS WELL AS DB NAMES OR SOMETHING.  
    ' ******** mAYBE A TABLE FIRST, AND FROM THERE THE ARRAY?
    
    
    MyArray = Array("ReportingDailyStats")
    
    'MyArray = Array("ReportingDailyStats", _
    '		"...", _
    '		)
    
    For each item in MyArray
    accObj.run item
    
    'accObj.run "ReportingDailyStats"
    
    
    Set objFile = objFSO.OpenTextFile(Log, ForAppending, True)
    If Err.Number <> 0 Then
        objFile.Writeline "Access Reporting of " & item & " failed somewhere ! " & Now _
    	& " " & Err.Number & " Error Description: " & Err.Description
        Err.Clear
    Else
        objFile.Writeline "Access Reporting of " & item & " was completed " & Now
        Err.Clear
    End If
    
    objFile.Close
    
    Next
    
    
    accObj.CloseCurrentDatabase
    
    
    'objFile.Close
    
    ' Clear memory
    
    Set accObj = Nothing
    Set objFSO = Nothing
    Set objFile = Nothing
    
    ' ****************
    
    'HERE'S THE ACCESS FUNCTION:
    
    Option Compare Database
    
    Public Sub ReportingDailyStats()
    
    
    'this is the actual send access report loop
    Dim strEmail As String
    Dim rs As ADODB.Recordset
    Dim strAssignee As String
    Dim blnOK As Boolean
    Dim msg As String
    Dim strName As String
    Dim strToList As String
    blnOK = True
    
    ' *******CHECK HERE THE EMAILS....  IF NEED TO CHANGE... CREATE DISTRIB TABLE
    strToList = "[email protected];[email protected]"
    
    Set rs = New ADODB.Recordset
    rs.Open "Select DISTINCT Assignee, EmailAddress from TblAssociates where State not like 'Sears' and [Reporting State] = 'Yes'", _
        CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    
    If rs.RecordCount > 0 Then
    
    ResumeClickYes
    rs.MoveFirst
    While Not rs.EOF
    strEmail = rs!emailaddress
    strAssignee = rs!Assignee
    msg = "Daily Performance Update for " & [strAssignee]
    
    DoCmd.OpenReport "Daily Performance Update - Use", acViewPreview, , "[Assignee] = '" & strAssignee & "'"
    DoCmd.SendObject acSendReport, , acFormatPDF, strEmail, , , msg, , False
    DoCmd.Close acReport, "Daily Performance Update - Use"
    
    rs.MoveNext
    
    Wend
    SuspendClickYes
    rs.Close
    Set rs = Nothing
    
    End If
    
    'this sends the full report to managers named in strToArray dimmed above
    ResumeClickYes
    DoCmd.SendObject acSendReport, "Daily Performance Update - Use", acFormatPDF, strToList, , , "Daily Performance Update", _
        "Please let me know if you see any inconsistencies, or the update dates do not fall within the last 12 hours.", 0
    DoCmd.Close acReport, "Daily Performance Update - Use"
    SuspendClickYes
    
    'this is for saving the report, if preferred
    'DoCmd.OutputTo acOutputReport, "Daily Performance Update - TESTJET", acFormatPDF, _
        "C:\home\Network Development\Regional Assistants\BackEnds\DiscvrRepSched\EMAIL\" _
            & "Daily Performance Update" & Format(Date, ShortDate) & ".pdf"
    
    Exit_ReportingDailyStats:
        Exit Sub
    
    Err_ReportingDailyStats:
        MsgBox Error$ & ": " & Err.Description
        SuspendClickYes
        Resume Exit_ReportingDailyStats
    
    End Sub

    ANY HELP IS GREATLY APPRECIATED!! I've got other reports that I'd like to automate once this one is working...

    Thanks! Be my savior!

    Jet

Check out some similar questions!

Automation of bulk mails in ms access 2007 [ 1 Answers ]

Hii Please can any one help in automation of sending bulk mails to different receipients which is already in the database,that is when certain data is selected in database the particular mail has to be automatically shooted to that particular recipient... as I am new to database as well as MS...

Automation error in MS Access [ 0 Answers ]

Hi, Please Help I am working with an Access database that was developed using Office 97 and was converted to the 2002-2003 Access file format. On this one form there are 26 text boxes (representing yearly pay periods) and on the “On Lost Focus” event for each text box the person who...

Access Reports [ 3 Answers ]

I need to dynamically size a text box in an access report, depending on the value of a field on that line. For some lines it must show the text box and others it mustn't. And it must be able to resize the text box depending on how much text I need to display. Is this possible in Access and How,...

MS Access Reports [ 4 Answers ]

Hello all, I need to make a report on access and I need a count of records, that will need to satisfy 2 conditions. For example: records should be counted if the on the Sex column is "M" and the rating column is "2". Any ideas? This is very easy if you filter the records on a table,...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.