problem in OnError...

Rameez

Registered User.
Local time
Tomorrow, 01:30
Joined
Jun 5, 2009
Messages
26
Here's a problem...i hope you can solve it...I don't understand where I am going wrong.

Function test1234(....)
On Error GoTo errorcode
...
...
docmd.runsql "........"
docmd.runsql "........"
Msgbox "executed successfully"
Exit Function
errorcode:
Msgbox "not executed"
End Function

The problem is on successful execution also the errorcode messagebox is showing up!!!!


Plz help me out....
 
you will have to show us the real code

as it stands this will work, and not jump to the error handler in normal circumstances

BUT

a) the error handler remain active, so an error somewhere else in your program would return here and show this error handler

change it to msgbox("Error: " & err & " Desc: " & err.description) to see what the error really is.

b) you MUST have a resume statement in the error handler - otherwise you remain in the error handler, and you cannot activate another error handler while you are handling the current error.
 
I am puttig the actual code....Please do help me out Gemma.

Private Sub cmdadd_Click()
On Error GoTo Error_Handle

Dim todaydate
todaydate = Now()
'setuser is a function already defined in another module.This works correct
Dim updater As String
updater = setuser()

'validations

If IsNull(Me.txtid) Or IsDate(Me.txtid) Then
MsgBox "Centre field can't be null or with date."
Exit Sub

ElseIf IsNumeric(Me.txtname) Or IsDate(Me.txtname) Or IsNull(Me.txtname) Then
MsgBox "Centre name field can't be null,numeric or a date field."
Exit Sub

ElseIf IsNumeric(Me.txtdname) Or IsDate(Me.txtdname) Or IsNull(Me.txtdname) Then
MsgBox "Director name field can't be null,numeric or a date field.", vbInformation, "Validation Error"
Exit Sub
ElseIf IsNumeric(Me.txtdhname) Or IsDate(Me.txtdhname) Or IsNull(Me.txtdhname) Then
MsgBox "Department Head name field can't be null,numeric or a date field.", vbInformation, "Validation Error"
Exit Sub
ElseIf IsNumeric(Me.txtmname) Or IsDate(Me.txtmname) Or IsNull(Me.txtmname) Then
MsgBox "Manager name field can't be null,numeric or a date field.", vbInformation, "Validation Error"
Exit Sub
End If
Me.Dirty = False
DoCmd.SetWarnings False
STATEMENT = "INSERT INTO Centre (Centre,Centre_Name,Director,Department_Head,Manager,Last_Updated_By,Last_Updated_Date) VALUES ('" & Me.txtid & "', '" & Me.txtname & "','" & Me.txtdname & "','" & Me.txtdhname & "','" & Me.txtmname & "','" & updater & "','" & todaydate & "')"
DoCmd.RunSQL STATEMENT
MsgBox "Record saved successfully", vbOKOnly, "NT SLA Tool"
Exit sub

Error_Handle:
MsgBox "There's another Center with the same number"
End Sub
 
Sorry Dave...

I missed to see the last line and called you Gemma...sorry :D
 
something else is tripping the error

change your

MsgBox "There's another Center with the same number"

to this

msgbox("Error: " & err & " Desc: " & err.description)

to see what the REAL ERROR is

--------
you also MUST have a RESUME statement in the error hanlder for reasons already expalined

----------
another way of examining your code is to add a breakpopint and step through the code.

you code is quite complex, and anything could be going wrong

eg, it is quite possible that this line is failing (because Access doesnt like something else in your record), and this is tripping the error

Me.Dirty = False

using a breakpoint and stepping through would be quite educational, and aid your general understanding of what is going on.
 

Users who are viewing this thread

Back
Top Bottom