Pasting Error Handler Into Module/Class Module

B

boborta

I would like to be able to be able to invoke code that will paste in a
standard error handler. The code is currently held in a text file. I
open this file and copy/paste it into places where needed - not already
done by Access. From time to time I have to customize this 'standard'
error handler, but that is okay. At work our PC's are locked down, so
add-ins cannot be installed. Does someone have a sample of code that
would do this?

Standard handler

'-------------------------------------------------------------
' Purpose:
'
' Author : XXX XXX, 04/07/06
' Employer
' Phone: XXX-XXX-XXXX
' E-Mail: (e-mail address removed)
' Notes :
' Tables:
' Forms:
' Reports:
' Calls:
'-------------------------------------------------------------
' Revision History
'-------------------------------------------------------------
'
'=============================================================
Dim dbe As DAO.DBEngine
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sql As String

On Error GoTo HandleErr

Set dbe = CreateObject("DAO.DBEngine.36")
Set db = CurrentDb()



ExitHere:
set db = nothing
set dbe = nothing
Exit Function

HandleErr:
MsgBox Err & ": " & Err.Description
Resume ExitHere

Thanks for you input.
 
E

Ed Adamthwaite

Hi Bob,
try this function, watch out for forced returns with your news-reader.
Edit it to suit your needs:

Function PrintDAO() As String
'Returns a standard DAO template to the debug window
Dim s As String
s = "On Error GoTo ErrorHandler" & vbCrLf _
& "Dim db As DAO.Database" & vbCrLf _
& "Dim rs As DAO.Recordset" & vbCrLf _
& "Dim s As String" & vbCrLf _
& "Dim sSQL As String" & vbCrLf & vbCrLf _
& "sSQL = " & Chr(34) & Chr(34) & vbCrLf _
& "'Debug.Print sSQL" & vbCrLf & vbCrLf _
& "Set db = CurrentDb" & vbCrLf _
& "Set rs = db.OpenRecordset(sSQL, dbOpenSnapshot) 'dbOpenDynaset
dbOpenForwardOnly" & vbCrLf _
& "With rs" & vbCrLf _
& " .MoveLast 'force error 3021 if no records" & vbCrLf _
& " .MoveFirst" & vbCrLf _
& " Do Until .EOF" & vbCrLf _
& " " & vbCrLf & vbCrLf _
& " .MoveNext" & vbCrLf _
& " Loop" & vbCrLf _
& "End With" & vbCrLf _
& "GoTo ThatsIt" & vbCrLf _
& "ErrorHandler:" & vbCrLf _
& " Select Case Err.Number " & vbCrLf _
& " Case 3021" & vbCrLf & vbCrLf _
& " Case Else" & vbCrLf _
& " MsgBox " & Chr(34) & "Problem with ()" & Chr(34) & " & vbCrLf
_" & vbCrLf _
& " & " & Chr(34) & "Error " & Chr(34) & " & Err.Number & "
& Chr(34) & ": " & Chr(34) & " & Err.Description" & vbCrLf _
& " End Select" & vbCrLf
s = s & "ThatsIt:" & vbCrLf _
& "rs.Close" & vbCrLf _
& "Set rs = Nothing" & vbCrLf _
& "Set db = Nothing"
PrintDAO = s
End Function
 
B

boborta

Thanks Ed. It did not occur to me to do it this way - I was thinking
high-tech solution when one was not necessary. I have honed it a
little and it works fine. Thank you for your help.

Bob
 

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