Go Back   Access World Forums > Microsoft Access Discussion > General

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-04-2019, 05:51 AM   #16
gstylianou
Newly Registered User
 
Join Date: Dec 2013
Posts: 190
Thanks: 33
Thanked 4 Times in 4 Posts
gstylianou is on a distinguished road
Re: Convert MsAccess report to PDF and save it in specific customer path

Quote:
Originally Posted by Minty View Post
You have commented out the create pdf part of your code ' DoCmd.OutputTo !
Yes because i was tried to test it. If you cancel the comments again you get the relative error...

(what a f.......day..!!)

gstylianou is offline   Reply With Quote
Old 06-04-2019, 06:04 AM   #17
gstylianou
Newly Registered User
 
Join Date: Dec 2013
Posts: 190
Thanks: 33
Thanked 4 Times in 4 Posts
gstylianou is on a distinguished road
Re: Convert MsAccess report to PDF and save it in specific customer path

Now, after the below modifications, i'm getting the correct message that the new PDF file was created on the correct Path (C:\DatabaseFiles\Patients\1\Test.pdf) but the file isn't there and i get the attached error..! Any new ideas?

Private Sub Command24_Click()
Dim FileName As String, fldrPath As String, filePath As String
Dim answer As Integer

FileName = "Test" 'filename for PDF file*
fldrPath = " C:\DatabaseFiles\Patients" & Me.CustomerNo & "" 'folder path where pdf file will be saved *

' filePath = fldrPath & "" & FileName & ".pdf"
' filePath = fldrPath & "" & FileName & ".pdf"

filePath = fldrPath & "" & FileName & ".pdf"
Debug.Print filePath

' If Not FolderExists(fldrPath) Then
' MkDir fldrPath
' End If

'check if file already exists
If FileExists(filePath) Then
answer = MsgBox(prompt:="PDF file already exists: " & vbNewLine & filePath & vbNewLine & vbNewLine & _
"Would you like to replace existing file?", buttons:=vbYesNo, Title:="Existing PDF File")
If answer = vbNo Then Exit Sub
End If

' On Error GoTo invalidFolderPath
DoCmd.OutputTo objecttype:=acOutputReport, objectName:=Me.Name, outputformat:=acFormatPDF, outputFile:=filePath

MsgBox prompt:="PDF File exported to: " & vbNewLine & filePath, buttons:=vbInformation, Title:="Report Exported as PDF"
Exit Sub
End Sub
Attached Images
File Type: jpg nwe.JPG (20.8 KB, 16 views)
gstylianou is offline   Reply With Quote
Old 06-04-2019, 06:16 AM   #18
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 6,307
Thanks: 153
Thanked 1,690 Times in 1,662 Posts
Minty is a jewel in the rough Minty is a jewel in the rough Minty is a jewel in the rough
Re: Convert MsAccess report to PDF and save it in specific customer path

What does Me.Name resolve to?
E.g. Add
Debug.Print Me.Name
to your code before that line.

__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
Old 06-04-2019, 06:34 AM   #19
gstylianou
Newly Registered User
 
Join Date: Dec 2013
Posts: 190
Thanks: 33
Thanked 4 Times in 4 Posts
gstylianou is on a distinguished road
Re: Convert MsAccess report to PDF and save it in specific customer path

Quote:
Originally Posted by Minty View Post
What does Me.Name resolve to?
E.g. Add
Debug.Print Me.Name
to your code before that line.
100% something much crazy..!!!!! Have a look to the attached pic.
Attached Images
File Type: jpg Untitled.jpg (92.0 KB, 18 views)
gstylianou is offline   Reply With Quote
Old 06-04-2019, 07:09 AM   #20
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,764
Thanks: 55
Thanked 1,022 Times in 988 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
Re: Convert MsAccess report to PDF and save it in specific customer path

DoCmd.OutputTo objecttype:=acOutputReport, objectName:=Me.Name, outputformat:=acFormatPDF, outputFile:=filePath


1. I am not sure about the red expression. May be correct, but may not.

More likely
2. You would get error 2501 if the report failed because of an error in the query. It's a generic "did not work" indicator. does the report open if you just try it outside this code block?
__________________
Dave (Male!)
Gemma was my dog

if a poster helps you, please click the scales at the bottom left of this posting, or use the thanks button alongside.
gemma-the-husky is offline   Reply With Quote
Old 06-04-2019, 07:18 AM   #21
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 6,307
Thanks: 153
Thanked 1,690 Times in 1,662 Posts
Minty is a jewel in the rough Minty is a jewel in the rough Minty is a jewel in the rough
Re: Convert MsAccess report to PDF and save it in specific customer path

Actually the active object is the report that is open, and the code is run from it.
I'm not sure you can reference it that way. Certainly your error is nothing to do with that.

Like I said, create a form with all your records and simply open a filtered report to that record and output it.

Your file process checking should be (in order)

1. Does the folder and subfolder exist, if not create it.
2. Does the file exist, if it doesn't simply create it.
2.1 If it does ask user if they want to overwrite it.
2.2 Create the file or exit based on their answer.
__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
Old 06-04-2019, 07:24 AM   #22
gstylianou
Newly Registered User
 
Join Date: Dec 2013
Posts: 190
Thanks: 33
Thanked 4 Times in 4 Posts
gstylianou is on a distinguished road
Re: Convert MsAccess report to PDF and save it in specific customer path

Quote:
Originally Posted by gemma-the-husky View Post
DoCmd.OutputTo objecttype:=acOutputReport, objectName:=Me.Name, outputformat:=acFormatPDF, outputFile:=filePath


1. I am not sure about the red expression. May be correct, but may not.

More likely
2. You would get error 2501 if the report failed because of an error in the query. It's a generic "did not work" indicator. does the report open if you just try it outside this code block?

Hi again,

About the objectName:=Me.Name should be ok because if you check the first attached accent file which is the original file the report can be saved into a simple path. So about that I think we are OK.

The report source it's from simple select query without any filtering with data. So, I don't think so that the problem it's because of that..Really I don't know what else I must try...

Havr you check the modified example on your Pc,? It's working normally ?

(I start think that maybe something happened with my office pack....2016 ProPlus 32bit)

gstylianou is offline   Reply With Quote
Old 06-04-2019, 12:20 PM   #23
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,764
Thanks: 55
Thanked 1,022 Times in 988 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
Re: Convert MsAccess report to PDF and save it in specific customer path

What I meant was - if you just open the report, to preview it, does it open, or do you get an error? If you get an error, trying to produce the report in code will give you error 2501

So your last post made me think - is this code INSIDE the report? if so that might be the problem.

you probably need a separate form with a button on - and then run that code from the button. I am not sure whether you can produce a pdf from a button on the report itself, and probably less likely from using code in design mode - although even that may be possible in later versions of access.

Alternatively you can open the report in preview mode, right-click it and then "save as pdf" from the short menu.
__________________
Dave (Male!)
Gemma was my dog

if a poster helps you, please click the scales at the bottom left of this posting, or use the thanks button alongside.
gemma-the-husky is offline   Reply With Quote
Old 06-04-2019, 09:42 PM   #24
gstylianou
Newly Registered User
 
Join Date: Dec 2013
Posts: 190
Thanks: 33
Thanked 4 Times in 4 Posts
gstylianou is on a distinguished road
Re: Convert MsAccess report to PDF and save it in specific customer path

Quote:
Originally Posted by gemma-the-husky View Post
What I meant was - if you just open the report, to preview it, does it open, or do you get an error? If you get an error, trying to produce the report in code will give you error 2501

So your last post made me think - is this code INSIDE the report? if so that might be the problem.

you probably need a separate form with a button on - and then run that code from the button. I am not sure whether you can produce a pdf from a button on the report itself, and probably less likely from using code in design mode - although even that may be possible in later versions of access.

Alternatively you can open the report in preview mode, right-click it and then "save as pdf" from the short menu.

Morning,

The report works without any error if run.
The VBA code run using a command button on the report. So after your last post maybe the problem is because of that?
You suggest to use a form and from there to call the procedures? If so, please explain how you thing is better to do that from a form?

1. First filtering data on the firm?
2. Run direct the code without open the report? If so, how can the doctor check his/her data on the report without open it?

Thanks again for your help and your time

Have a nice day!
gstylianou is offline   Reply With Quote
Old 06-04-2019, 10:18 PM   #25
June7
Newly Registered User
 
June7's Avatar
 
Join Date: Mar 2014
Posts: 1,951
Thanks: 0
Thanked 462 Times in 458 Posts
June7 will become famous soon enough June7 will become famous soon enough
Re: Convert MsAccess report to PDF and save it in specific customer path

Report open in PrintPreview is not interactive, command buttons are not clickable. Buttons are clickable in ReportView but ReportView not exportable. So, conventional approach is code behind form to:

1. Open report
2. OutputTo pdf
3. Close report

Viewing filtered data on form may be one way to preview data that will output to report. Although, reports can be more complex and not actually look like form display.

But why should user need to look at report before output? User just needs to select filter criteria. If they really want to preview, then open in PrintPreview and let them right click Export.
__________________
Attach File Manager is below Advanced editor window, click Go Advanced below Quick Reply window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
DEBUG! DEBUG! DEBUG!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
June7 is offline   Reply With Quote
Old 06-04-2019, 11:23 PM   #26
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,764
Thanks: 55
Thanked 1,022 Times in 988 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
Re: Convert MsAccess report to PDF and save it in specific customer path

@june

thanks for that explanation. I am not completely familiar with the newer versions of Access. I realised you could now put buttons on reports, but hadn't researched them at all.

@gstylianou. In that case the error 2501 is happening because you aren't allowed to open (run) the report to prepare a pdf the way you are trying to - so the report fails, and 2501 is just a general "failed" message that isn't so helpful. Access probably doesn't know the code you are using is "in the report" - so it can't provide a more helpful message.

The easiest way is either to have button on a form to use the code you are using (but it won't be me.name - you will need the name of the report) - or to preview the report, and save it from there if you want a pdf.

I think you need to try some things instead of trying to get a chapter and verse solution. We don't know how your trying to design your app interface - we are just aware of what might be causing your problem.
__________________
Dave (Male!)
Gemma was my dog

if a poster helps you, please click the scales at the bottom left of this posting, or use the thanks button alongside.
gemma-the-husky is offline   Reply With Quote
Old 06-05-2019, 12:28 AM   #27
Minty
AWF VIP
 
Minty's Avatar
 
Join Date: Jul 2013
Location: UK - Wiltshire
Posts: 6,307
Thanks: 153
Thanked 1,690 Times in 1,662 Posts
Minty is a jewel in the rough Minty is a jewel in the rough Minty is a jewel in the rough
Re: Convert MsAccess report to PDF and save it in specific customer path

@OP - See post #21 we are all suggesting the same thing.

Create a form with cmd buttons to either preview the whole report, or select a specific record and export it.
__________________
If we have helped please add to our reputation - click the scales symbol on the left, tick 'I approve' and leave a comment.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Minty is offline   Reply With Quote
Old 06-17-2019, 10:33 PM   #28
riti90
Newly Registered User
 
Join Date: Dec 2017
Location: Cambridge, United Kingdom
Posts: 28
Thanks: 20
Thanked 2 Times in 2 Posts
riti90 is on a distinguished road
Re: Convert MsAccess report to PDF and save it in specific customer path

I use this code on a button:
Quote:
On Error GoTo Err_mySUB

Dim thisFile As String
thisFile = CurrentDb.Name
thisFile = Mid(thisFile, InStrRev(thisFile, "") + 1)
thisFile = Left(thisFile, Len(thisFile) - 6)

Dim DBPath As String
DoCmd.SetWarnings False
DBPath = CurrentProject.Path & ""
DoCmd.OpenReport "YOUR-REPORT", acViewPreview, , , acHidden
DoCmd.OutputTo acOutputReport, "YOUR-REPORT", acFormatPDF, DBPath & thisFile & "_Report" & ".pdf", True
DoCmd.Close acReport, "YOUR-REPORT", acSaveYes
DoCmd.SetWarnings True


Exit_mySUB:
Exit Sub
Err_mySUB:
MsgBox Err.Number & ": " & Err.Description & " (" & Erl & ")"
Resume Exit_mySUB

riti90 is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] MSOffice convert MSAccess 2010 32-Bit for MSAccess 2013 64-Bit PtrSafe LongPtr Rx_ Modules & VBA 2 12-11-2015 06:15 AM
Using DoCmd.OutputTo to save as pdf with specific name but want user to choose path ML! Reports 3 11-09-2010 06:56 AM
Question How to start MsAccess using specific version of MsAccess? davidiew General 3 05-28-2009 12:20 AM
Add record-specific image from specific path to report mafhobb Reports 7 12-19-2008 07:15 PM
Save MSaccess report as PDF luckyloser Modules & VBA 1 10-27-2008 10:31 AM




All times are GMT -8. The time now is 12:56 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World