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

Design - error raising and using 'custom error constant'

Status
Not open for further replies.

deebowyer

Programmer
Jun 6, 2005
8
0
0
GT
My question here is partly a design problem and partly a error problem.

I use a DLookup in the BeforeUpdate event of a form to verify whether the new entry is a valid primary key- ie, unique.
My own warning box pops up and Cancel is executed if the key is not unique.

This allows the user to return to the form and edit their entry, thus not losing the rest of the data in the form.

This all functions decently.
The problem is this:
When the close button is clicked(I do have custom close buttons and disabled the standard ones for other reasons) and the key is not unique, the msgbox pops up, BUT, when the Ok button is clicked,the form simply exits.

I can live with this but I am sure there must be a way to capture this Close event and have a warning msgbox thrown out.

I am visualising if I could make the above code part of the error handling, there might be a way to detect that 'there is an error raised AND the form is closing, so don't just put the usual warning box up, but put up a 'Ok or Cancel' message box, and either Ok-close form and discard data or Cancel- cancel the onUnload event.

I am thinking of using the raise method, but I can't figure out what the error number should be so I don't conflict with existing errors and possible cause confusion by raising existing errors.
If I catch this XXXX error, I have this blind faith that I might be able to do more with the close event than if I am simple popping a 'Ok' msgbox from ordinary codespace.

I am not sure I am even on the right track with all of this.

Thank you
 
All of these situations may be somewhat different. In this thread, thread702-866344, I suggested something that may address what you're after, or at least discussing events that may come into consideration in such context. There are also other suggestions that may point you in the direction you need. Then there's also mstrmage1768's faq faq702-1870. I have a feeling what you're after may very well something along these lines.

Roy-Vidar
 
Thank you. I have been studiing the thread for a few days, but had not come across the FAQ.

Do you know if it is possible to view the Err object's constants of error codes. I have not been able to locate something using the Object browser, though found other objects that seem to suggest it might be possible if one could locate this 'object'(I don't know exactly the word for it)

I will dig in and try to see what I can figure out.

gracias
 
Have a look at vbObjectError

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

I did go looking for this object. If I have 'all libraries' listed, it should show up in the Object browser, right? It would be part of the vba library I imagine.

It doesn't show. Not sure why that is. Access 2000 on XP but I doubt any of that has much to do with anything.

Thanks
 
In the debug window (Ctrl+G) type raise and hit the F1 key.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
To find at least for the AccessErrors, you could use a loop and

[tt]debug.print AccessError(lngCounter)[/tt]

Using PHV's suggestion, in the help file for the Raise method of the err object, be sure to follow the link to Example.

Did you also see this thread thread702-1080271, with regards to "trapping" thingies like this? I may of course be wrong...

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top