473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Export a report to the current desktop in pdf format

547 512MB
I would like to always export a particular report as a pdf document to the current "desktop" of that specific PC, without hardcoding the "user" of that computer in the vba. My current vba is:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "Drugusage", acFormatPDF, , True
Any suggestions please
Dec 14 '12 #1

✓ answered by Seth Schrock

I remembered where I had used the DoCmd.OutputTo in one of my databases so I tested my theory on that and what I had in my previous post didn't work. So I tested my other idea and it did work. Here it is:
Expand|Select|Wrap|Line Numbers
  1. Dim strUserName As String, strPath As String
  2.  
  3. strUserName = Environ("username")
  4. strPath = "C:\Users\" & strUserName & "\desktop\Drugusage.pdf"
  5.  
  6. DoCmd.OutputTo acOutputReport, "Drugusage", acFormatPDF, strPath, True
I had to manually put in your information so you might check that I have typed everything correctly.

12 14878
Seth Schrock
2,965 Expert 2GB
I don't know if this works in VBA, but in windows scripting the %username% takes the place of the user name in the file path. It might be something to look into.

Edit: If this is something that will have to work across Win XP & 7, just know that the file path is different for each OS. XP uses Documents and Settings while 7 uses Users. I'm not sure how to tell the database which path to use. I normally make a folder on the C:\ drive and then make a shortcut on the desktop to that folder if I need to. It simplifies the VBA end.
Dec 14 '12 #2
neelsfer
547 512MB
It will be for different windows 7 machines only.
Dec 14 '12 #3
Seth Schrock
2,965 Expert 2GB
Okay. I don't have a test database to work with, but you could try the following:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "Drugusage", acFormatPDF, "C:\Users\%username%\Desktop\Drugusage.pdf", True
If that doesn't work I have another idea, but lets start with that for now.

--**DOES NOT WORK**-- Moderators can remove post.
Dec 14 '12 #4
Seth Schrock
2,965 Expert 2GB
I remembered where I had used the DoCmd.OutputTo in one of my databases so I tested my theory on that and what I had in my previous post didn't work. So I tested my other idea and it did work. Here it is:
Expand|Select|Wrap|Line Numbers
  1. Dim strUserName As String, strPath As String
  2.  
  3. strUserName = Environ("username")
  4. strPath = "C:\Users\" & strUserName & "\desktop\Drugusage.pdf"
  5.  
  6. DoCmd.OutputTo acOutputReport, "Drugusage", acFormatPDF, strPath, True
I had to manually put in your information so you might check that I have typed everything correctly.
Dec 14 '12 #5
neelsfer
547 512MB
Thx a Seth it works great !!! I have also tried it for a database of mine
Dec 14 '12 #6
Seth Schrock
2,965 Expert 2GB
Just curious, are you working with Neelsfer on this?
Dec 14 '12 #7
neelsfer
547 512MB
Seth you are a star. It is working as i expected it to work
Dec 14 '12 #8
Seth Schrock
2,965 Expert 2GB
Not a problem neelsfer. It was actually exciting for me because this is one of just a few times where I have been able to take pieces from other puzzles and put them together and make a whole new picture :) I have used different part of my code in separate databases, but never together so it was nice to see it all come together so nicely.
Dec 14 '12 #9
zmbd
5,501 Expert Mod 4TB
YEA Seth!
It was only a matter of time!

As for the environment variable: "%USERPROFILE%\Desktop"
It has been this since windows97 and continues thru windows7. I have not had a hand's on with windows8. I typically use this to place a document in the users' document folder.

As for a longer term solution (and something I've considered moving to): http://msdn.microsoft.com/en-us/libr...ffice.10).aspx I believe that ADezii will have a better handle on that method.
Dec 14 '12 #10
NeoPa
32,556 Expert Mod 16PB
FYI: CJFer was a temporary account Neels (neelsfer) used when his main one was temporarily unavailable.
Dec 14 '12 #11
NeoPa
32,556 Expert Mod 16PB
It would be harsh to reset the Best Answer, but I would suggest Seth remember Z's solution for future use. It is preferable, and more reliable, as it doesn't presuppose the user's profile is under C:\Users (Which actually reflects a relatively recent change in fact - Windows7 and forward only).
Dec 14 '12 #12
Seth Schrock
2,965 Expert 2GB
I skimmed the website enough to know that I will have to go back when I have more time, so I have put it in my favorites to make it easier to find and also reference the next time I want to do something like this (which might be soon).
Dec 14 '12 #13

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

Similar topics

0
by: Olya | last post by:
I'm developing reports with using Crystal Report Viewer on ASP.NET. After I have report done I try to export it to .PDF format and get the following error: "Error in File...
1
by: Majstor | last post by:
Does anybody know how to export Report in Word, Excel or HTML with pictures (Access 2000)? I don't use snapshot format.
7
by: Li Pang | last post by:
Hi, I built a web form to display a crystal report in web, every thing work properly. I added then a button to display the report in the embedded adobe reader by using the below codes: Dim...
2
by: jpr | last post by:
Friend, I am using a code to export data from a table to a word document using bookmarks and have a problem with a date format. When I export a field that is a mm/dd, in my word doc it shows up...
0
by: Mariana | last post by:
Hello, I am exporting reports in pdf format from .net 2005 . The export is working fine; however the user values of stored procedure parameters does not show in the report. What do I need to do in...
4
by: Joe Schmo | last post by:
Is there any way to export an Access Report, including the format, into a Word document - other than printing to a PDF.
17
by: 1q2w3e4r5t6y7u8i | last post by:
Hi, I am printing an invoice through the following code: dim cr as new crystalreport1 cr.PrintToPrinter(1, False, 1, 1) the problem is that the complete paper cames out. I want to print...
8
by: muddasirmunir | last post by:
is there any way or third party utility which can export our data report to pdf format i am usinig vb6 i know crystal report can do that but i had a project with data report is there any way to...
1
by: ttfitz | last post by:
I have an application developed in Access 2000, to be distributed as an MDE. For those folks without Access, they install the free Access 2007 runtime. For the most part, this seems to be working...
2
by: ghiey | last post by:
hi to all, i have searched for a solution regarding exporting access 2007 reports to excel file. i have converted to access 2007 my database from access 2003. i guess microsoft omitted the ease...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
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...

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.