Print Report to PDF, no selection (1 Viewer)

velcrowe

Registered User.
Local time
Yesterday, 23:56
Joined
Apr 26, 2006
Messages
86
I am trying to place a command button on my form that will convert a report to pdf. I can e-mail through adobe. My issue that I don't want to select a report from a list as setup successfully by Leban. I would like the code to be setup to print the only report needed from my form. In this case it's rptTblUser. How can I modify the code from Leban to print this way? Thanks in advance

blRet = ConvertReportToPDF(Me.lstRptName, vbNullString, _
Me.lstRptName.Value & ".pdf", False, True, 150, "ABC", "DEF", tr, 0)

I believe I need to replace the Me.lstRptName with the actual name of the report. I am not comfortable enough with the syntax to do so
 

HiTechCoach

Well-known member
Local time
Yesterday, 22:56
Joined
Mar 6, 2006
Messages
4,357
I use Leban's code. I have not every had to modify his code.

See if this example will help:
Sending Emails To A Group, One Person At A Time
** I understand that this example may do more that you need, but it does show how to handle what you need. Hopefully you can modify the code to your needs.
 

irish634

Registered User.
Local time
Yesterday, 23:56
Joined
Sep 22, 2008
Messages
230
I use Leban's code. I have not every had to modify his code.

I use Leban's code as well, though I found I had to modify it slightly. It's usually my preference to construct a menu bar dedicated to the application I am building, so at times I may export a report to pdf without having any forms, reports, or db window open/visible. Doing this generates error number 2046 - [FONT=Verdana, Arial, Helvetica]"OutputTo isn't available"

As soon as I open a report, form, or show the db window the code executes flawlessly. I can duplicate this error at will.

[/FONT][FONT=Verdana, Arial, Helvetica]What I found was a Microsoft bug where a form, report, DB Window, etc has to be visible in order for the "OutputTo" command to work.

http://support.microsoft.com/default.aspx/kb/q244695/

Even though the article only shows the "OpenForm" or "OpenReport" functions, I found it to be true with OutputTo as well.

When I discovered this, I was using a menubar I created instead of forms or a switchboard, so nothing was open except the application window. If I have a form or db window visible in the application the code works fine. As soon as I close all forms and hide the db window, I try to call the code from the menu bar and whamo--- I get error 2046.

My solution to the Lebans code is this. Find the ConvertReportToPDF function and scroll down to this line:
Code:
    DoCmd.OutputTo acOutputReport, RptName, "SnapshotFormat(*.snp)", _  
       strPathandFileName
I fixed the issue by showing the DB window, then immediately hiding it again after the OutPutTo was complete:

Code:
    '-------------------------------------------------------------------------  
    '   Added by me to fix the Error 2046 error  
    '   Unhides the db window  
    '-------------------------------------------------------------------------  
    DoCmd.SelectObject acForm, "frm_UserLogin", True  
      
    ' Export the selected Report to SnapShot format  
    DoCmd.OutputTo acOutputReport, RptName, "SnapshotFormat(*.snp)", _  
       strPathandFileName  
    ' Make sure the process has time to complete  
    DoEvents  
      
    '-------------------------------------------------------------------------  
    '   Added by me to fix the Error 2046 error  
    '   Hides the DB Window  
    '-------------------------------------------------------------------------  
    DoCmd.SelectObject acForm, "frm_UserLogin", True  
    DoCmd.RunCommand acCmdWindowHide
[/FONT]
[FONT=Verdana, Arial, Helvetica] Once I did this, I no longer get error 2046 "OutputTo isn't available"
Hopefully it will work for others as well.

Craig
[/FONT]
 

HiTechCoach

Well-known member
Local time
Yesterday, 22:56
Joined
Mar 6, 2006
Messages
4,357
Craig,

That is very interesting. Thank you for sharing this information. I have not had this issue yet, but thanks to you, I should be able to handle it with ease.
 

irish634

Registered User.
Local time
Yesterday, 23:56
Joined
Sep 22, 2008
Messages
230
Craig,

That is very interesting. Thank you for sharing this information. I have not had this issue yet, but thanks to you, I should be able to handle it with ease.

You are welcome.
You should be able to duplicate it very easily. Export a report to PDF or a table to excel with only the application window visible.

If also found that this happens when I try to output a table to excel when nothing is visible. I have another DB that the user wants to output the data to excel and the same error occurs. So I show the DB window then hide it immediately after.

I have never found a KB article about "OutputTo" but the one I provided in my first post pointed me in the right direction, because I was experiencing similar issues.

It really has nothing to do with the Leban's code, it just appears to be a Microsoft quirk. I just happen to show the db window, but in reality all you need to do is show "something" whether it's a form, report, etc.

Craig
 

irish634

Registered User.
Local time
Yesterday, 23:56
Joined
Sep 22, 2008
Messages
230
I believe I need to replace the Me.lstRptName with the actual name of the report. I am not comfortable enough with the syntax to do so

If you are trying to output the single report just replace Me.lstRptName with your report name.

So if your report name is for example rptStatistics you would put "rptStatistics" in place of Me.lstRptName

Remember to use quotes.
 

HiTechCoach

Well-known member
Local time
Yesterday, 22:56
Joined
Mar 6, 2006
Messages
4,357
You are welcome.
You should be able to duplicate it very easily. Export a report to PDF or a table to excel with only the application window visible.

If also found that this happens when I try to output a table to excel when nothing is visible. I have another DB that the user wants to output the data to excel and the same error occurs. So I show the DB window then hide it immediately after.

I have never found a KB article about "OutputTo" but the one I provided in my first post pointed me in the right direction, because I was experiencing similar issues.

It really has nothing to do with the Leban's code, it just appears to be a Microsoft quirk. I just happen to show the db window, but in reality all you need to do is show "something" whether it's a form, report, etc.

Craig

Craig,

With what version(s) of Access has this happen?
 

irish634

Registered User.
Local time
Yesterday, 23:56
Joined
Sep 22, 2008
Messages
230
Craig,

With what version(s) of Access has this happen?

Boyd,

I can duplicate this in:

  1. Access 2000 which I have here at work.
  2. Access 2003 which I have at home.
I am unsure of the other versions. I suppose I could try it in 2007 runtime to see what happens.

Craig
 

Users who are viewing this thread

Top Bottom