Err.Number = 3022 (1 Viewer)

wazz

Super Moderator
Local time
Tomorrow, 04:16
Joined
Jun 29, 2004
Messages
1,711
hi. i'm trying to create my own error message and me.undo for err 3022 and can't get it going. i found a couple of threads from 2001 and 2002 that should have worked but aren't doing it for me. has something changed since then? i've tried putting the code with the control, the subform, the main form, in the main body of the code, in the error trapping, the beforeupdate event and on error event. the code should be simple right?:
Code:
ErrorHandler:
    If Err.Number = 3022 Then
        MsgBox "Duplicate..."
    Else
        MsgBox "Error Number: " & Err.Number & vbCrLf & _
        etc.
    End If
does it matter that there is nothing in the main body of the code? any help and/or code would be much appreciated. - w.
 

boblarson

Smeghead
Local time
Today, 13:16
Joined
Jan 12, 2001
Messages
32,059
Wazz:

What is the complete code that you are trying to use (including the On Error GoTo...) and what event are you putting it on?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:16
Joined
Sep 12, 2006
Messages
15,640
you can have an error handler in any event code, where you are doing something that may cause an error

eg if in a before update you ae doing a dlookup to see if the entry already exists, put a error handler in there in case it fails for some reason.

however if you try to close a form with a dirty record, and the insert or update fails with a duplicate key say (is that 3022 - not sure off hand) you can trap this with a generic error handler in the forms error event

these sort of things are tricky to get right as you can get the error called in several places eg control error event handler, form generic event handler, and say form before update event, and sonetimes its hard to dismiss all of them at the same time
 

Banana

split with a cherry atop.
Local time
Today, 13:16
Joined
Sep 1, 2005
Messages
6,318
you can have an error handler in any event code, where you are doing something that may cause an error

To be pedantic, you don't have to, as long the error handling routine encompass all subroutines.

For example, let's say we have two modules, form and subform, and the subform has two routines, one is form event and another is a control event.

The barest minimum needed to handle error is to place an generic error handler in the form's OnError event.

So if something went wrong in subform's control event, the routine would be saying, "What the hell is this? I don't know how to handle it. Here, you take it", tossing the error up to the subform's form event which has no clue, and toss it up to the form, which is trapped on OnError event.

That said, it does make sense to have specialized error handling for certain routines to allow for more control and giving more specific information with a generic error handler as a final bailout.

Also, I'm pretty sure you can only have one error raised at a time. You cannot have a multiple errors at same time. In sequence, yes, but not at same time.

Wazz- at first I decided I'd wait to see your complete code, but suddenly remembered something- I had same problem last year, and was told that it may be because we're not seeing a VBA error but rather an Access error. Can you verify if this is an error generated by Access (e.g. a duplicate record being created in process without any code). If this is the case, then if my memory serves, this cannot be trapped as you would with VBA and may indicate a need for form redesign...
 
Last edited:

wazz

Super Moderator
Local time
Tomorrow, 04:16
Joined
Jun 29, 2004
Messages
1,711
Access Error

thanks for the replies. the only code i have so far is what you see. there is nothing going on in the form at all, so far. (the error is coming from the subform). the On Error GoTo goes to the error handler you see and the only part missing is to resume errorhandlerexit.
Wazz- at first I decided I'd wait to see your complete code, but suddenly remembered something- I had same problem last year, and was told that it may be because we're not seeing a VBA error but rather an Access error. Can you verify if this is an error generated by Access (e.g. a duplicate record being created in process without any code). If this is the case, then if my memory serves, this cannot be trapped as you would with VBA and may indicate a need for form redesign...
this is very possible. i'm getting an error message without an error number - it looks like an Access error, i presume, and not my own error message. i did design this form in a slightly unusual way. still, the error is straightforward and i thought i could trap it easily enough. :eek: i'll play with the form itself a bit and check back again. tnx all.
 

boblarson

Smeghead
Local time
Today, 13:16
Joined
Jan 12, 2001
Messages
32,059
What I would do is to set a breakpoint at the start of everything and F8 through until you get the error. That should help isolate what is causing it.
 

Banana

split with a cherry atop.
Local time
Today, 13:16
Joined
Sep 1, 2005
Messages
6,318
thanks for the replies. the only code i have so far is what you see. there is nothing going on in the form at all, so far. (the error is coming from the subform). the On Error GoTo goes to the error handler you see and the only part missing is to resume errorhandlerexit.this is very possible. i'm getting an error message without an error number - it looks like an Access error, i presume, and not my own error message. i did design this form in a slightly unusual way. still, the error is straightforward and i thought i could trap it easily enough. :eek: i'll play with the form itself a bit and check back again. tnx all.

Okay, now that we know that this is an Access error, it usually indicates a problem with your recordsource. For example, if you have a query as a recordsource, and you're linking together two table, one which is a junction, and you've made the mistake of using primary key from the one side table rather than many side table, you will get that error when you try to create a record using the same primary key (as Access will try to store the primary key in a new record in the same table, which trips the error of duplicate key). Change that key from one side table to many table, then it'll work.

Hope that's a clue toward solving the problem.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:16
Joined
Sep 12, 2006
Messages
15,640
the other thing is that a error handler stays "live" until its superseded by another, so an error may be jumping back unexpectedly to the last defined error handler.

I would definitely trace the program executrion as Boblarson suggests
 

wazz

Super Moderator
Local time
Tomorrow, 04:16
Joined
Jun 29, 2004
Messages
1,711
tnx again for the replies. the problem seems fixed now. unfortunately i went ahead and changed several things at once so i'm not sure which fix solved the problem. :rolleyes: sry about that. i'm pretty sure that the (main) problem was what banana suggested though - using the wrong key-field in the form. this is something *i* always have to watch for. thanks for all ideas.
 

Users who are viewing this thread

Top Bottom