Need Error Trapping Help

R

Renee Moffett

The following code allows users to click a button to export a cover page and
attachment to their desktops. It had worked fine for over a year. Then I
had to modify it because we are getting new machines and the name of the
desktop is different on the new ones. It will be a year before everyone in
the office is again on the same system. The simplest way appeared to be to
first try to output to the D drive (old machines). Since the new machines
don't have a D, there would be an error and the error handler would tell it
to output to C.

In doing this, I found that the existing 'OutputTo' lines of code had an
error all along that I was unaware of, although the end result worked and
the files were produced on the desktop. I never knew about this error, but
now that I do I'm at a loss what to do about it.

I either need to find the source of the error and fix it...or since it
doesn't seem to effect the end result, can I trap error 2302 and ignore it
and go to the error handler for all other errors?

Here is the code in question. And THANK YOU!

Private Sub ExportButton_Click()
On Error GoTo ExportButton_Click_Err:
If IsNull(Me.IntOrdNumber) Then
Exit Sub
Else
Dim sPath As String
Dim sCovName As String
Dim sAttName As String
Dim UserName As String
DoCmd.RunCommand acCmdSaveRecord
fOSUserName 'Calls module to capture User Name for use in sPath
sCovName = Me.IntOrdNumber & " Cover.snp"
sAttName = Me.IntOrdNumber & " Attach.xls"
sPath = "C:\WINNT\Profiles\" & fOSUserName & "\Desktop\"
'C & D Drive Machines
DoCmd.OutputTo acOutputQuery, "qryDirOrderDetailsTPPAttach",
acSpreadsheetTypeExcel8, sPath & sAttName, True
DoCmd.OutputTo acOutputReport, "rptTPP Order Form", "Snapshot", sPath &
sCovName, True

ExportButton_Click_Err:
'C Drive Machines
sPath = "C:\Documents and Settings\" & fOSUserName & "\Desktop\"
DoCmd.OutputTo acOutputQuery, "qryDirOrderDetailsTPPAttach",
acSpreadsheetTypeExcel8, sPath & sAttName, True
DoCmd.OutputTo acOutputReport, "rptTPP Order Form", "Snapshot", sPath &
sCovName, True
MsgBox "Your Cover Page and Attachment exported to your desktop as " &
sCovName & sAttName
End If
End Sub
 
R

Renee Moffett

Thanks. This helped.


B Fuller said:
acOutputQuery, "qryDirOrderDetailsTPPAttach",
acOutputQuery, "qryDirOrderDetailsTPPAttach",




Assuming I understand the question:


ExportButton_Click_Err:
If err.number = 2302 then
exit sub (or use a goto command)
else
MsgBox Err.Description
End if

You could also set the error code so that if the error is
2302, it then tries to save to a different directory by
using the same code under the if/then statement.

BFuller
 

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