Calling a modual on error

JBurlison

Registered User.
Local time
Today, 16:47
Joined
Mar 14, 2008
Messages
172
i have a module, and im still new to VB so i do not know how to call on it when a error happens. also i would like it to also report what form they where on when the error occur d how can i record this?


Code:
    Dim db As DAO.Databaset
    Dim rserror As DAO.Recordset

    Set db = CurrentDb
    Set rserror = db.OpenRecordset("Errors", dbOpenDynaset)

    MsgBox "The program has encounterd a error! The error has been recorded and sent to the database admin, ''Error: " & Err.Description & " Error Number: " & Err.Number & "''. " & "If you have received the error Invalid use of Null, please make sure that all the required fields are not empty.", vbCritical + vbOKOnly, "Error!"

    With rserror
        .AddNew
        .Fields("Error Reason") = Err.Description
        .Fields("User") = Forms![InfoKeeper]![Loginname]
        .Fields("Error Number") = Err.Number
        .Update
    End With
    rserror.Close
    Set rserror = Nothing
 
Create a function to put the code in (within a Standard Module) and then in the error handler just use:

Call WhateverYouCalledTheFunction
 
I think in order to write good error handling code you need to understand the basics very well.
Do not expect this to happen overnight…it will take years.
 
How do i put the form name that the error happened on?
 
In your error handling code include a variable like this:
Code:
Public Function LogError(strForm As String, strErrDesc As String, strErrNum As String) 
    ...do your logging here
End Function

And then call it by using

Code:
Call LogError(Me.Name, Err.Description, Err.Number)
 
Okay I have similar problem with this. I tried to copy the code for my situation. Now it is asking me for the Variable strClaim.

Code:
Public Function DnDelete(strClaim As Long)


'declare the variable
Dim sql As String

'Declare the SQL statement to use and the variables
sql = "DELETE * FROM tblDNclaims WHERE ClaimNo =  strClaim"
  
'Execute the SQL statement
DoCmd.RunSQL sql

End Function

I call it by

Code:
DnDelete (Me.ClaimNo)

This whole process is being run from a command button on a form.

- ClaimNo is a Number in the data type.

-There is a front side and back side to this DB as well if that helps.

-Not sure if I need to set up a connection to back side or not. When I have the code on the form it works as desired. I am trying ot put it in a module so it can be accessed from multiple forms.

any help would be greatly appreciated.
 
Last edited:
Try

sql = "DELETE * FROM tblDNclaims WHERE ClaimNo = " & strClaim

By the way, it is sort of counter-intuitive to prefix a variable with "str" if it's an Integer.
 
pbaldy - thank you so much.... I am still learning or should say new to this.

I know about the varibale naming, I will change that now that I know what the datatype will be. I started off with it as a string.
 

Users who are viewing this thread

Back
Top Bottom