473,473 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Create 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 1980
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
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, ,...
0
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...
1
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. ...
3
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...
1
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...
1
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...
2
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...
3
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",...
9
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...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.