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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Module called from Macro to Create and Output Report -Report is Blank

Status
Not open for further replies.

gvngrace

Technical User
Jun 1, 2011
2
CA
From a form, "frmRunAudit", I have a command button set to 'On Click' run macro, "Step 2 Run Compare." The "Step 2 Run Compare" has several RunCode lines defined. Each RunCode line Function Name is defined within a Public Function in Module, "RunCompare."
The first line of the Macro and Module are defined below.
I can run the Module manually and the report will create, with valid data, and save to the defined directory.

When this is called from the macro a blank report is created and saved to the defined directory.

I have 5 reports that should create. All are blank when called from the macro, but manually within the module all is good.

I searched and found a post detailing the References that should be set. I have confirmed these are set.
Visual Basic For Applications, Microsoft Access 11.0 Object Library, OLE Automation, Mirosoft DAO 3.6 Object Library, Microsoft ActiveX Data Objects 2.1 Library, Microsoft Visual Basic for Applications Extensibility 5.3, Microsoft Outlook 11.0 Object Library, Microsoft Scripting Runtime

Running MS Access 2003 SP3
Running Windows XP Professional SP3

Not sure where to go from here to resolve.
Thank you!

Code:
Macro "Step 2 Run Compare"
Action        FunctionName
RunCode       cmdCreateSiteCAPFILERPT_Click()
Code:
Module "RunCompare"
Option Compare Database
Public Function cmdCreateSiteCAPFILERPT_Click()
'Create Capture Report from [QueryCaptureFile Import] filter by center number and save to archive\reports for EmailNotifications
    ' Create Variables for Subroutine
    Dim strDocName As String    'Report Name
    Dim strfileName As String    'File Name
    Dim db         As Database  'Database to retrieve data from
    Dim strSQL     As String    'SQL Statement
    Dim rst        As Recordset 'Data Recordset
    Dim strFilter  As String    'Report Filter
    Dim centernum As String
    Dim strPathAndFile As String
    Dim rstlast As String
  
   
Const strPath = "C:\AuditDB\Archive\Reports\" 'This is where the reports will be stored prior to email
  
    ' Set Values for Variables
strDocName = "rptCaptureFile ImportTBL" 'this is the report that is the template
strSQL = "SELECT [c_CenterNum] FROM [CaptureFile Import] ORDER BY [c_CenterNum]"
strfileName = " Capture Report"
Set db = CurrentDb
Set rst = db.OpenRecordset(strSQL) ' Open recordset containing list of center numbers
    
    If Not rst.EOF Then ' Test recordset and act accordingly
        rst.MoveFirst 'Go to first record of recordset
        Do Until rst.EOF 'Setup loop to loop through
        If rstlast <> rst(0) Then
        strFilter = "[c_CenterNum]= " & rst(0) 'Set the report filter property, zero base array
        strPathAndFile = strPath & rst(0) & strfileName & ".snp" 'sets the report type
        DoCmd.OpenReport strDocName, acViewPreview, , strFilter
        DoCmd.OutputTo acOutputReport, strDocName, acFormatSNP, strPathAndFile
        DoCmd.Close acReport, strDocName, acSaveNo
                    
        End If
            
        rstlast = rst(0)
        'Move to next
        rst.MoveNext
  
        'Loop back to top of Do Until
        Loop
  
    Else
    ' No Sales Reps Exist, inform the user and exit subroutine
        MsgBox "No Reports to Save"
        Exit Function
    End If
  
Exit_cmdCreateSiteCAPFILERPT_Click:
    Exit Function
  
Err_cmdCreateSiteCAPFILERPT_Click:
    MsgBox Err.Description
    Resume Exit_cmdCreateSiteCAPFILERPT_Click
  
End Function
 
After posting question I re-reviewed all tables as I stepped through the form, "frmRunAudit", from the beginning.

The AuditDate is not populating, resulting in the empty reports.

Creating new thread for this new issue, after I search FAQs and other posts.
Thank you!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top