Snapshot Report

  • Thread starter brownti via AccessMonster.com
  • Start date
B

brownti via AccessMonster.com

I am using the below code:

Public Function saveRptsToSNP()

On Error GoTo ErrHandler

Dim rpt As Report
Dim sPath As String
Dim idx As Long

sPath = CurrentProject.Path & "\"

For idx = 0 To (Reports.Count - 1)
Set rpt = Reports(idx)
DoCmd.OutputTo acOutputReport, rpt.Name, acFormatSNP, _
sPath & rpt.Name & ".SNP", False
Next idx

Exit Function

ErrHandler:

MsgBox "Error in saveRptsToSNP( )." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Function

And would like to first check if a folder exists in that directory with the
name of a textbox. if it doesnt exists, i would like to create that folder
and then save the snap shot in that folder with the name in the textbox
followed by the date. How should i change this code to make that happen?
THank you!
 
D

dch3

You'll want to use the FileSystemObject. The sample code pretty much does
what you need, but you'll need to adapt it accordingly.
..FileExists and .CreateFolder are the two key methods.

Dim fso
Dim targetFolder
Dim folderExists
Set fso = createObject("Scripting.FileSystemObject")

'87
targetFolder = "C:\\Documents and Settings\\All Users\\Documents\\Trailer
Management and Manifest"
folderExists = FSO.FolderExists(targetFolder)
'90
if folderExists = False then
fso.CreateFolder targetFolder
end if
targetFolder = "C:\\Documents and Settings\\All
Users\\Documents\\Trailer Management and Manifest\\Application"
'95
folderExists = FSO.FolderExists(targetFolder)

if folderExists = False then
fso.CreateFolder targetFolder
end if
 
D

Douglas J. Steele

Why bother with FSO? It's doable using strictly VBA.

targetFolder = "C:\Documents and Settings\All Users\Documents\Trailer
Management and Manifest"
If Len(Dir(targetFolder, vbDirectory) = 0 Then
' Folder doesn't exist
MkDir targetFolder
End If

Neither method will let you create multi-level directories. In other words,
if you're trying to create C:\Folder1\Folder2, Folder 1 must already exist.
 
D

dch3

Habit

Douglas J. Steele said:
Why bother with FSO? It's doable using strictly VBA.

targetFolder = "C:\Documents and Settings\All Users\Documents\Trailer
Management and Manifest"
If Len(Dir(targetFolder, vbDirectory) = 0 Then
' Folder doesn't exist
MkDir targetFolder
End If

Neither method will let you create multi-level directories. In other words,
if you're trying to create C:\Folder1\Folder2, Folder 1 must already exist.
 

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

Top