Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputing to RTF WITHOUT save prompt

Status
Not open for further replies.

BYarn

MIS
Jul 20, 1999
131
US
I know I have done this before and I've looked all over but can't remember how (the price of senior moments!)

This is Access97. I have a macro to quit a form (actually one to quit and another to exit access). When the user clicks on the button (one to quit and another to exit) to execute the macros, 2 reports are output to a specific RTF file. That works the 1st time, but the second and subsequent times the user is prompted for a YES or NO to replace existing file.

How can I have the file saved without a prompt (ie, just overwrite the existing file??) I thought it was done on the "Output File" line of macro (eg, "h:\access\data\myfile.rtf" with a yes or Y following that)


???

Thanks
 
I made this file for a mailmerge process. You can adapt/rewrite the error messages as needed. Basically, it will delete the file if it exists. If it doesn't exist, you don't see an error. If the file is locked, it prints an error message.

Code:
Public Sub AttemptToDeleteFile(strFilename As String)
On Error GoTo Sub_Error
    
    Kill strFilename
    
Sub_Exit:
    Exit Sub
    
Sub_Error:
    If Err.Number = 53 Then 'err 53 = file not found, that means the file is already deleted!
        'no error, continue
        Resume Sub_Exit
    ElseIf MsgBox("Cannot delete file.  Close all Word mailmerge documents and click Retry.", vbRetryCancel, "File In Use") = vbRetry Then
        Resume
    Else
        Err.Clear
        Err.Raise vbObjectError + 1024 + 1, "file in use", "File In Use@" & _
                    "Cannot complete the mailmerge process because the file '" & strFilename & "' " & _
                    "is in use.  Close all Word mailmerge documents and try again."
        Resume Sub_Exit
    End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top