View Full Version : how to get Caption of current control for errmodule


vinzz
05-29-2008, 08:44 AM
hi,

i'm trying to make an errmodule so i can see in a table when a user makes a fault other then 0.
i have this as err in each function:
Call ErrorDB(me.caption)
and a module:
Public Function ErrorDB(errctl As String)
Dim db As Database
Dim LSQL As String
Dim errnum As String
Dim errdesc As String
errnum = Err.Number
errdesc = Err.Description
If Err.Number <> 0 Then
Set db = CurrentDb()
LSQL = "insert into tblerrors (Gebruiker,errnummer,erromschrijving,erronForm,err onctrl) values ('" & NaamGebruiker & "','" & errnum & "','" & errdesc & "','" & CurrentObjectName & "','" & errctl & "')"
db.Execute LSQL, dbFailOnError
On Error GoTo 0
Set db = Nothing
MsgBox errdesc, vbCritical, errnum
End If
End Function

i'm trying to get the current control name (caption) to set in the tablecolumn "erronctrl". I tried alot in the function caller like:
Call ErrorDB(me.caption)
Call ErrorDB(ctl.caption)
Call ErrorDB(ctl.tag)
Call ErrorDB(ctl.controls.caption)
But without any succes. Does anyone knows how to get the caption name (or function name) where the error occured.

thanks in advance :P

greetz
Vincent B.

evanscamman
05-29-2008, 05:50 PM
I just used this code by Allen Browne to add error handling to my app.

http://www.everythingaccess.com/tutorials.asp?ID=Error-Handling-in-Access-Basic

It writes each error to a table very nicely, but you must supply the function with a string that contains the name of the calling procedure.

Evan

vinzz
05-30-2008, 03:51 AM
yeah, it's the same system as mine, only mine is better and simple :P, i just have to change one thing and i have exact the same function.

If i change this:
Call ErrorDB("some err text here for current procedure")

I want a function that automatically get the caption name and place it in the database in the column erronctrl.
But if this isn't possible, i will use this function like above (mine works with the parameter above

gemma-the-husky
05-30-2008, 07:07 AM
active control is probably as simple as

myname = screen.activecontrol.name

vinzz
05-30-2008, 08:06 AM
i'll check it out and let you know if it works