473,587 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DoCmd.OutputTo Root folder question (Access)

72 New Member
Hi, the following code seem to work fine if the user picks a folder in the root drive. If they select the root HDD the strPathPDF becomes (eg M:\)

M:\\ProductList .pdf

The file gets created but is it correct?? What am I missing?
Thanks




Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCreatePDF_Click()
  2.     On Error GoTo ErrorHandler
  3.  
  4.     Dim strWHERE As String
  5.     Dim strPathPDF As String
  6.     Dim reportName As String
  7.     Dim fDlg As Object
  8.  
  9.     Set fDlg = Application.FileDialog(4)
  10.  
  11.     If Not IsNull(Me.ctlHomeChild.Form!ProductID) Then
  12.         strWHERE = Me.ctlHomeChild.Form.Filter 'Use the filter from the calling form.
  13.         reportName = "rptProductList"
  14.  
  15.         With fDlg
  16.             .Title = "Select a folder"
  17.             .AllowMultiSelect = False
  18.             .InitialFileName = "C:\"
  19.             If .Show = -1 Then
  20.                 strPathPDF = .SelectedItems(1) & "\" & "ProductList.pdf"
  21.  
  22.                 Debug.Print strPathPDF
  23.  
  24.                 DoCmd.OpenReport reportName, acViewReport, , strWHERE, acHidden
  25.  
  26.                 With Reports(reportName)
  27.                     Caption = "Product List Report " & Date
  28.                     .FilterOn = True
  29.                 End With
  30.  
  31.                 DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, strPathPDF, False, , , acExportQualityPrint
  32.                 DoCmd.Close acReport, reportName
  33.  
  34.             End If
  35.         End With
  36.     Else
  37.         Beep
  38.     End If
  39.  
  40. exitSub:
  41.     Exit Sub
  42. ErrorHandler:
  43.     MsgBox "Error No: " & Err.Number & vbNewLine _
  44.          & "Error Details: " & Err.Description & vbNewLine _
  45.          & "Error in Sub: frmProducts_Database\cmdCreatePDF_Click"
  46.     Resume exitSub
  47.  
  48. End Sub
Apr 2 '20 #1
5 1989
twinnyfo
3,653 Recognized Expert Moderator Specialist
Neruda,

I'm not sure we can answer your question:
Neruda:
The file gets created but is it correct??
We don't know if it is correct. are you getting reports from your users that the files is incorrect? This is where we must start.
Apr 6 '20 #2
ADezii
8,834 Recognized Expert Expert
It is because you are appending a Trailing Backslash to the Selected Folder (.SelectedItems (1)) which would not be appropriate should it be the Root Folder (C:\). Insert Lines 180 - 220 to correct this. This Code Segment could be shortened, but I kept it in this format for illustration purposes. Some Code has also been omitted.
Expand|Select|Wrap|Line Numbers
  1. 100 Dim strPathPDF As String
  2. 110 Dim fDlg As Object
  3.  
  4. 120 Set fDlg = Application.FileDialog(4)
  5.  
  6. 130 With fDlg
  7. 140  .Title = "Select a folder"
  8. 150  .AllowMultiSelect = False
  9. 160  .InitialFileName = "C:\"
  10. 170     If .Show = -1 Then
  11. 180       If Right$(.SelectedItems(1), 1) = "\" Then
  12. 190         strPathPDF = .SelectedItems(1) & "ProductList.pdf"
  13. 200       Else
  14. 210         strPathPDF = .SelectedItems(1) & "\" & "ProductList.pdf"
  15. 220       End If
  16. 230     End If
  17. 240 End With
Apr 6 '20 #3
Neruda
72 New Member
@twinnyfo
Hi What I mean I expected the path to be M:\
But I end up with M:\\
But it seems id does not make much difference, even if the path is M:\\\\\\\ it works just fine. I was just wondering if I was missing something in the code
Apr 7 '20 #4
Neruda
72 New Member
I changed it as suggested anyway, thank u ADezii
Apr 7 '20 #5
ADezii
8,834 Recognized Expert Expert
You're welcome, good luck with your Project!
Apr 7 '20 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3137
by: Frank Barnhart | last post by:
We have an application which runs Access under automation. With Access 97, the app included this line to send a report to a text file: myAccessObject.DoCmd.OutputTo acOutputReport, , acFormatTXT, "sample.txt" (The constant acOutputReport has the value of "MS-DOS Text (*.txt)". There is no object name in the command because the report is open at the time this line is executed.)
0
1591
by: Robert Langen | last post by:
I'm calling an Access XP application from an Outlook XP appointment form. Everything works, but the lines DoCmd.OutputTo acOutputReport, "testreport", acFormatRTF, "c:\test.rtf", False Docmd.Quit produce Access hangs. That means, the file testreport.rtf is correctly created, but Access doesn´t quit. The process msaccess.exe stays and consumes 98% processor time. If I remove the OutputTo line, Access quits perfectly.
1
5310
by: Ryan | last post by:
Hello. I was hoping that someone may be able to assist with an issue that I am experiencing. I have created an Access DB which imports an Excel File with a particular layout and field naming. Next the user can go into a Form which basically a dynamic query with a friendly interface that eventually outputs a table that is stored in the DB as well as exported to a CSV file. The CSV file is then used with a vendor solution to fill in...
3
5491
by: ljungers | last post by:
I need to make some changes to a Query/select/print report using word application. What I need to do is change the way Word is called yet keep the process the same. Word is used so changes can be made before actual printing. Need some way of calling Word as a mail merge with the information from an Access table that the current report uses. I have seen mail merge templates that use something like <<field name>> in them that uses a table....
1
6265
by: Simon | last post by:
Dear reader, With the DoCmd.OutputTo ...... you have the possibility to write a report to an external location. In case the external location is an existing file the DoCmd is not responding with the warning "File already exist". The file will be overwrite without any warning even with the DoCmd.Setwarnings True in
1
5170
by: inika301 | last post by:
Mr Lebans. Could you help me ? We are trying to run your mdb to convert access reports to pdf but we can not, because an error happens. We are just using the A2000SnapShotToPDFver751 that is abailable for downloading. I have copied the two dlls to windows/system32 and they are too in the same path as the mdb. I have debuged your code and in the proc.ConvertReportToPDF when running command DoCmd.OutputTo... an error occurs.
2
3752
by: jmartmem | last post by:
Greetings, I have several Access 2007 reports that I regularly export to individual PDF flat files on a web server. I've successfuly created a module sub to export the reports using the DoCmd.OutputTo Macro action, but I can't seem to figure out how to run the macro automatically. I can succesfully run the macro below manually (without the IF statements), but have yet to make it work with the IF statement. Ideally, the macro will run...
3
1865
by: James Bowyer | last post by:
I need to only print one page of a report, not the whole thing, but do so automatically. Annoyingly, I can't seem to get it to work! This: DoCmd.OutputTo acOutputReport, "rptmouldcurrent", acFormatPDF, "C:\Temp\Test.pdf", False works ok, but prints out all reports, not just the one I want. So, I tired this:
9
4151
by: ChipStewart | last post by:
I'm trying to use a few posts from this forum, including use DoCmd.OutputTo to export a PDF of the current record on a report? to send a single record displayed in a form of my potential client data to a text file to use with Outlook and QuickBooks. I have a button on the form and the following code: Private Sub Export_Potential_Client_Data_Click() On Error GoTo Err_Export_Potential_Client_Data_Click Dim stDocName As String ...
0
7924
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7854
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.