output to excel (1 Viewer)

slimjen1

Registered User.
Local time
Today, 10:03
Joined
Jun 13, 2006
Messages
562
All, Using 2010. I am working on a database that was created in 2003. I created a form with a button to export a report to the users desktop in a folder name "Reports". Both the user and myself have access 2010 running on a win 7 machine. When I click the button; the code runs as expected and exports the report in the folder. When the user clicks the button, they get an error :"...can't save the output data to the file you've selected." Here's the code:

Code:
Private Sub Export_QA_Report_Click()
On Error GoTo Err_Export_QA_Report_Click

Dim reportname As String
Dim theFilePath As String
reportname = "rptQAReport"
theFilePath = "C:\Documents and Settings\" & Environ("UserName") & "\Desktop\Reports\"
theFilePath = theFilePath & reportname & "_" & Format(Date, "yyyy-mm-dd") & ".xls"


DoCmd.OutputTo acOutputReport, reportname, acFormatXLS, theFilePath, True
MsgBox "Look on your desktop for the report."

    
Exit_Export_QA_Report_Click:
    Exit Sub

Err_Export_QA_Report_Click:
    MsgBox Err.Description
    Resume Exit_Export_QA_Report_Click
    
End Sub

Why can't the users run it and I can?
Thanks
 

JHB

Have been here a while
Local time
Today, 16:03
Joined
Jun 17, 2012
Messages
7,732
Could it be because the path doesn't exist on the other users computer (or users are not allowed to save documents in the drive/path)?

Try to export it only to "C:\".
 

slimjen1

Registered User.
Local time
Today, 10:03
Joined
Jun 13, 2006
Messages
562
Thank you for your response. You are correct; users do not have access to the path. I need it to go to their desktop or they have access to My Computer. Any suggestions? Thanks
 

pr2-eugin

Super Moderator
Local time
Today, 15:03
Joined
Nov 30, 2011
Messages
8,494
Is the path to Desktop not
Code:
[COLOR=Red][B]C:\Users\[COLOR=Green]<USER NAME>[/COLOR][COLOR=Black]\Desktop\Reports\[/COLOR][/B][/COLOR]..
Why have you constructed the path as..
Code:
 [COLOR=Red][B]C:\Documents and Settings\[COLOR=Green]<USER NAME>[/COLOR][COLOR=Black]\Desktop\Reports\
[/COLOR][/B][/COLOR]
 

slimjen1

Registered User.
Local time
Today, 10:03
Joined
Jun 13, 2006
Messages
562
Thank you for your reply. Some of the users have Win xp. But I will try this path.
Thanks
 

jkl0

jkl0
Local time
Today, 10:03
Joined
Jun 23, 2006
Messages
192
You can just use the environment variable for windows 7,

%USERPROFILE% = C:\Users\{username}
 

slimjen1

Registered User.
Local time
Today, 10:03
Joined
Jun 13, 2006
Messages
562
I still get the error. Maybe because the users do not have access to docs and settings or their users folder. I don't know if that's the problem and/or do not know how to get around it.
thanks
 

slimjen1

Registered User.
Local time
Today, 10:03
Joined
Jun 13, 2006
Messages
562
You can just use the environment variable for windows 7,

%USERPROFILE% = C:\Users\{username}

? Do I use this as is? "%USERPROFILE% = C:\Users\{username}"

Umm. Still doesn't work. What am I doing wrong?
 

jkl0

jkl0
Local time
Today, 10:03
Joined
Jun 23, 2006
Messages
192
I don't have a Windows 7 machine to test this on, but try

Dim strUser as String
strUser = Environ("USERPROFILE")
theFilePath = strUser & "\Desktop\Reports\"
 

slimjen1

Registered User.
Local time
Today, 10:03
Joined
Jun 13, 2006
Messages
562
Doesn't work. Still getting the same error. Maybe I should export the query instead but this seems that it can work with output report. Don't know what to do. It's got to be something with the path but I've tried different ways to export it.
 

Users who are viewing this thread

Top Bottom