Error on Executing Report based on query and with filtered criteria ..

farhanleos

Registered User.
Local time
Yesterday, 16:22
Joined
Oct 19, 2017
Messages
38
Greetings ,

Gentlemen i am using below code on all command buttons to execute the report in pdf format , but i got Error while i did the same with the report which is based on Query and i have filter criteria on query?
Please guide if anybody have solution for this

ERROR : Runtime Error '2509'
MicrosoftAccess cannot find the object '|1'.
on Debug it leads to this script
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFilePath

Actual script using for :
Private Sub Command50_Click()
''''Open C1 Projects Under P&TSD/CPM Report in Pdf'''
'initialize variables
Dim strReportName As String
Dim strPathUser As String
Dim strFilePath As String
'set variables
strReportName = "006-C1 Projects Under P&TSD-CPM"
strPathUser = Environ$("USERPROFILE") & "\my documents"
strFilePath = strPathUser & strReportName & Format(Date, "yyyymmdd") & ".pdf"
'export to PDF/EXCEL
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFilePath
'launch excel file
Dim Shex As Object
Set Shex = CreateObject("Shell.Application")
Shex.Open (strFilePath)
End Sub
 
I am going to hazard a guess that strReportname has |1 as a value.
use debug to walk through the code step by step.
 
As well as debugging, check whether
- that report exists
- that folder path exists on your computer
Either of those being missing would cause the error

Also you appear to be using Excel to open PDF files.
I didn't know Excel could do that.
It seems an odd choice even if its possible.
 
Error on this part:
strPathUser = Environ$("USERPROFILE") & "\my documents"

Should be:
strPathUser = Environ$("USERPROFILE") & "\Documents"
 
Error on this part:
strPathUser = Environ$("USERPROFILE") & "\my documents"

Should be:
strPathUser = Environ$("USERPROFILE") & "\Documents"

sir, you are right i think inplace of my documents only docuemtns
but i check my all existing reports which i am poplulating by other command button are the same with my documents and
those are working
 
Sir I update the code but having same error & it leads me to
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFilePath


Private Sub Command50_Click()
''''Open C1 Projects Under P&TSD/CPM Report in Pdf'''
'initialize variables
Dim strReportName As String
Dim strPathUser As String
Dim strFilePath As String
'set variables
strReportName = "006-C1 Projects Under P&TSD-CPM"
strPathUser = Environ$("USERPROFILE") & "\Documents"
strFilePath = strPathUser & strReportName & Format(Date, "yyyymmdd") & ".pdf"
'export to PDF/EXCEL
DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFilePath
'launch excel file
Dim Shex As Object
Set Shex = CreateObject("Shell.Application")
Shex.Open (strFilePath)
End Sub
 
What does Debug.Print show ???

Code:
Private Sub Command50_Click()
''''Open C1 Projects Under P&TSD/CPM Report in Pdf'''
'initialize variables
Dim strReportName As String
Dim strPathUser As String
Dim strFilePath As String
'set variables
strReportName = "006-C1 Projects Under P&TSD-CPM"
strPathUser = Environ$("USERPROFILE") & "\Documents"
strFilePath = strPathUser & strReportName & Format(Date, "yyyymmdd") & ".pdf"
'export to PDF/EXCEL

[COLOR=Red]Debug.Print strReportName
Debug.Print strFilePath[/COLOR]

DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFilePath
'launch excel file
Dim Shex As Object
Set Shex = CreateObject("Shell.Application")
Shex.Open (strFilePath)
End Sub
 

Users who are viewing this thread

Back
Top Bottom