CurrentProject.Path problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I use the code:
DoCmd.OutputTo acReport, "Report Name", "SnapshotFormat(*.snp)",
Me!txtSNPdirectory & "\Report Name" & ".snp", True, ""
to export reports in SNP format.
txtSNPdirectory is a textbox that reads a field value from a table. When the
value is C: or H:\SNP\ or something similar the file is stored to the
relevant location but when the value is CurrentProject.Path it doesn’t work
to store the file in the folder where the application resides as I should
expect.
Can you see where the mistake is?

Thanks
GL
 
How exactly do you use CurrentProject.Path?

DoCmd.OutputTo acReport, "Report Name", _
"SnapshotFormat(*.snp)", _
CurrentProject.Path & "\Report Name" & ".snp", True, ""

should create a file named ReportName.snp in the same folder as your MDB,
unless your MDB is at the root of a drive. That's because
CurrentProject.Path will return C:\ or D:\ when the file's in the root, and
you'll end up with two slashes in a row. To catch this, use:

Dim strPath As String

strPath = CurrentProject.Path
If Right$(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If

DoCmd.OutputTo acReport, "Report Name", _
"SnapshotFormat(*.snp)", _
strPath & "\Report Name" & ".snp", True, ""
 
The problem is not the root directory.
I write the SNP file path and save it in a table where the value is read
from the textbox then I use the content of the textbox to pass the path to
the DoCmd.OutputTo function.
When I save in the table a phrase like C:\path\ is OK but when I save the
phrase CurrentProject.Path it doesn’t work.
 
I'll repeat, then: how are you using CurrentProject.Path in your code?

Copy and paste your code that doesn't work...
 
GL said:
Hi,

I use the code:
DoCmd.OutputTo acReport, "Report Name", "SnapshotFormat(*.snp)",
Me!txtSNPdirectory & "\Report Name" & ".snp", True, ""
to export reports in SNP format.
txtSNPdirectory is a textbox that reads a field value from a table.
When the value is C: or H:\SNP\ or something similar the file is
stored to the relevant location but when the value is
CurrentProject.Path it doesn't work to store the file in the folder
where the application resides as I should expect.
Can you see where the mistake is?

Are you trying to use the literal "CurrentProject.Path" as the value for
the field? That won't work. In similar cases, I use the character "."
as the first character of the value, and have code that checks for a
leading "." and replaces it with the value returned by
CurrentProject.Path -- like this (air code):

Dim strPath As String

strPath = Me!txtSNPDirectory

If Left(strPath, 1) = "." Then
strPath = CurrentProject.Path & Mid(strPath, 2)
End If

DoCmd.OutputTo _
acReport, _
"Report Name", _
"SnapshotFormat(*.snp)",
strPath & "\Report Name" & ".snp", _
True, _
""
 
Dirk you are wright I have tried to use the literal "CurrentProject.Path" as
the value of the field that feeds the textbox.
Thanks for your resolving code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top