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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with a function 2

Status
Not open for further replies.

tomvdduin

Programmer
Sep 29, 2002
155
NL
Hi,

I have a function log_error that logs errors into a table. But I can't get it to work. This is the function:

Function log_error(user As String, error_nr As Integer, error_descript As String, active_object As String)
On Error GoTo error_trap

Dim cnn As Connection
Dim rst As New ADODB.Recordset
Dim x As Integer

Set cnn = CurrentProject.Connection
cnn.BeginTrans
DisplayMessage (Date & " en " & Time & " en " & CurrentUser & " en " & Err.Number & " en " & Err.Description & " en " & Screen.ActiveControl)
rst.open "tbl_STD_errorlog", cnn, adOpenKeyset, adLockOptimistic, adCmdTableDirect
rst.AddNew
rst!datum = Date
rst!tijd = Time
rst!user = CurrentUser
rst!error_nr = error_nr
rst!error_descript = error_descript
rst!active_object = active_object
rst.Update
cnn.CommitTrans

x = MsgBox("This program has become an error. Please warn your system administrator", vbCritical, "Meerkerk Ledensysteem Error")

Exit_form:
Exit Function

error_trap:
cnn.RollbackTrans
MsgBox Err.Description
Resume Exit_form

End Function

and this is how I call the function:

log_error(CurrentUser, Err.Number, Err.Description, "frm_ETIKETTEN_selectie")

It seems right, not? But I get a compile error saying: 'expected =', but the function haven't got a return value set. So I changed the function call in

Function log_error(user As String, error_nr As Integer, error_descript As String, active_object As String) as Integer

and used:
Dim x as Integer

x = log_error(CurrentUser, Err.Number, Err.Description, "frm_ETIKETTEN_selectie")

then, when I compile, I got a warning 'types don't match' and log_error is highlighted.

What's wrong?

greetz

Tom
 
Your function type isn't declared... It therefor returns a variant. Two possible sollutions:

1) Declare your functions to return an integer:

Function log_error(user As String, error_nr As Integer, error_descript As String, active_object As String) AS INTEGER

2) Or; declare your x as a variant.

Dim x as variant
--------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
deprnds on how you derive the 'error_nr', but the data type for 'ERR' is long, not integer


MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Tnx 4 the answers. the error_nr derives from err.number, so I made that a long.

both the options of NVSbe gives the same error: types don't match, with the word log_error highlighted. So it meens that the types of x and the function don't match, witch I am sertain that they're the same.

I tried to use public sub instead of function, but that gives the same problem.

any other solutions are always welcome!
 
I was a bit hasty in reading your post. The reason you get "expected =" is because you use brackets. Calling it like so:

log_error CurrentUser, Err.Number, Err.Description, "frm_ETIKETTEN_selectie"

or

call log_error(CurrentUser, Err.Number, Err.Description, "frm_ETIKETTEN_selectie")

should not get that message.

About the types don't match thing: It might be an assignment in the function that causes this. You might want to look at those.
--------------------------------------
It's not the monsters under your bed, it is the men next door.
That make you fear, make you cry. Make you cry for the Child.
All the wars are fought amongst those lonely men. Unharmed, unscarred.
 
I was able to get this to run w/o err by removing the DisplayMessage line/function and changing the err to long. Just to suit my style, I changed some names of vars and table struct, but those were strictly cosmetic.

MichaelRed
m.red@att.net

Searching for employment in all the wrong places
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top