Overwriting files

D

Dar

I am using the outputto command for reports in snapshot format.
I do not want to overwrite existing reports that have the same name.
I would like to get the message, "do you want to overwrite existing file?"
and have the user select no. I've checked for SetWarnings but can only find
them in macro which I have added SetWarnings On but this did not solve
problem.
Any other suggestions would be helpful.
 
W

Wayne-I-M

Hi

Best bet would be to rename the report each time.

You can create a file folder (say in My Documents for example).
If you have 2 reports (call ReportA and ReportB) you would rename them each
time so in your new folder you would have

ReportA-12/12/2007
ReportA-13/12/2007
ReportA-15/12/2007
ReportA-02/01/2008
ReportB-12/12/2007
ReportB-23/12/2007
ReportB-03/02/2008
etc
etc

Of course if you export more than once a day you could just add the time
ReportA-02/01/2008 - 10:05am
ReportA-02/01/2008 - 03:23pm

etc
etc






-- Wayne
Manchester, England.
 
D

Douglas J. Steele

Try something like:

Dim strFileName As String

strFileName = "F:\Folder\File.snp"

If Len(Dir(strFileName)) > 0 Then
If MsgBox(strFileName & " exists." & vbCrLf & _
"Do you want to delete it?", vbYesNo + vbQuestion) = vbYes Then
Kill strFileName
End If
End If
 
D

Dar

This is the concept I would like, however, I don't want to kill the file I
want to be able to add a Date to the filename.
Example, I want JohnDoe 10/10/08.snp
I've tried putting it in existing DoCmd.Output but get error message, not
enough disk space for temporary file. I'm sure its syntax, just don't know
what.
 
D

Dar

Private Sub SendHMO_Click()
DoCmd.OutputTo acOutputReport, "rptDischargeSummary", acFormatSNP, _
"H:\Therapy\OTPT\HMO\OT\Discharges\" & Me.txtResident & ".snp", False


End Sub
 
D

Douglas J. Steele

Private Sub SendHMO_Click()

Dim intAttempts As Integer
Dim strFileName As String

intAttempts = 0
strFileName = "H:\Therapy\OTPT\HMO\OT\Discharges\" & _
Me.txtResident & ".snp"

Do While Len(Dir(strFileName)) > 0
Select Case intAttempts
Case 0
strFileName = "H:\Therapy\OTPT\HMO\OT\Discharges\" & _
Me.txtResident & _
Format(Date, "mm\-dd\-yyyy") & ".snp"
Case 1
strFileName = "H:\Therapy\OTPT\HMO\OT\Discharges\" & _
Me.txtResident & _
Format(Now, "mm\-dd\-yyyy hh\-nn\-ss") & ".snp"
Case 2
Msgbox "Sorry, I can't come up with a unique name."
Exit Sub
End Select
intAttempts = intAttempts + 1
Loop

DoCmd.OutputTo acOutputReport, "rptDischargeSummary", acFormatSNP, _
strFileName, False

End Sub
 
D

Dar

Thanks, I haven't tried this yet, but......don't swear, but I failed to
mention that the date I actually want is taken from the report which has a
field called txtDate which is not always the current system date etc, rather
the date the report was written. So the Snapshot report is JohnDoe
10/06/08.snp Can I include the txtDate field in the syntax of the Output ?
 
D

Douglas J. Steele

Private Sub SendHMO_Click()

Dim strFileName As String

strFileName = "H:\Therapy\OTPT\HMO\OT\Discharges\" & _
Me.txtResident & ".snp"

If Len(Dir(strFileName)) > 0 Then
strFileName = "H:\Therapy\OTPT\HMO\OT\Discharges\" & _
Me.txtResident & " " & Me.txtDate & ".snp"
If Len(Dir(strFileName)) > 0 Then
Msgbox "Sorry, I can't come up with a unique name."
Exit Sub
End If
End If

DoCmd.OutputTo acOutputReport, "rptDischargeSummary", acFormatSNP, _
strFileName, False

End Sub

Note that you cannot include slashes in a file name, so if txtDate actually
contains 10/06/08, you'll need

strFileName = "H:\Therapy\OTPT\HMO\OT\Discharges\" & _
Me.txtResident & " " & _
Replace(Me.txtDate, "/", "-") & ".snp"
 
D

Dar

Doug, I think that is the problem I was having. I'll replace the slashes
and I thank you for your response.
 

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

Similar Threads


Top