Error on Executing Report based on query and with filtered criteria .. (1 Viewer)

farhanleos

Registered User.
Local time
Today, 09:59
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:59
Joined
Sep 21, 2011
Messages
5,122
I am going to hazard a guess that strReportname has |1 as a value.
use debug to walk through the code step by step.
 

isladogs

CID Moderator
Staff member
Local time
Today, 17:59
Joined
Jan 14, 2017
Messages
12,574
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.
 

arnelgp

error reading drive A:
Local time
Tomorrow, 00:59
Joined
May 7, 2009
Messages
8,813
Error on this part:
strPathUser = Environ$("USERPROFILE") & "\my documents"

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

farhanleos

Registered User.
Local time
Today, 09:59
Joined
Oct 19, 2017
Messages
38
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
 

farhanleos

Registered User.
Local time
Today, 09:59
Joined
Oct 19, 2017
Messages
38
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
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:59
Joined
Sep 21, 2011
Messages
5,122
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 (Users: 0, Guests: 1)

Top Bottom