A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Error handling question



 
 
Thread Tools Display Modes
  #11  
Old October 3rd, 2005, 05:02 PM
BruceM
external usenet poster
 
Posts: n/a
Default

If I have a command button for SendObject that opens an e-mail, and if I
then click the X at the top right of the e-mail without sending it, I will
get an Error 2501 (the Send Object action was canceled, or something like
that) message if I do not trap the error.

"Rick Brandt" wrote in message
t...
BruceM wrote:
There may be a blank message before this one. I think I clicked the
Send button too soon.

Thanks for responding. I like the idea of the custom function, since
I often need to trap Error 2501, but I'm not quite certain how to
make it work. If I have a command button for SendObject (to send an
e-mail, for instance), and if the user decides against sending the
e-mail, how do I trap that when opening the form? Would I make a
function to trap 2501, then call the function in place of the If ...
End If part of the ProcErr code? Or am I missing your point?


Not sure I understand the question. If you are pressing a button that
calls
SendObject what does that have to do with opening a form?

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com




  #12  
Old October 3rd, 2005, 05:39 PM
Fred Boer
external usenet poster
 
Posts: n/a
Default

Thanks, Rick!


Fred

"Rick Brandt" wrote in message
t...
Fred Boer wrote:
Dear Rick:

Any chance you might share those functions?


Pretty basic stuff really (once you see them I'm sure you'll agree).

The one for the report adds an option for Fit-To-Window, You will have to
replace my custom ErrorMessages function with whatever you normally use
for
displaying error messages.


'Wrapper for DoCmd.OpenForm that ignores error 2501
'*******************************************
Public Function fnOpenForm(stFormName As String, _
Optional lngView As Long =
acNormal, _
Optional stFilterName As
String, _
Optional stWhereCondition As
String, _
Optional lngDataMode As Long =
acFormPropertySettings, _
Optional lngWindowMode As Long
= acNormal, _
Optional stOpenArgs As String)
As Boolean

On Error GoTo ErrHandler

DoCmd.OpenForm stFormName, lngView, stFilterName, stWhereCondition,
lngDataMode, lngWindowMode, stOpenArgs
fnOpenForm = IsLoaded(stFormName)

Egress:
Exit Function

ErrHandler:
Select Case Err.Number
Case 2501
'ignore
Case Else
ErrorMessages "fnOpenForm Function"
End Select
Resume Egress
End Function

'Wrapper for DoCmd.OpenReport that ignores error 2501
'*********************************************
Public Function fnOpenReport(stReportName As String, _
Optional lngView As Long =
acViewNormal, _
Optional stFilterName As
String, _
Optional stWhereCondition As
String, _
Optional FitToWindow As
Boolean) As Boolean

On Error GoTo ErrHandler

DoCmd.OpenReport stReportName, lngView, stFilterName, stWhereCondition
fnOpenReport = IsRptLoaded(stReportName)
If FitToWindow = True Then DoCmd.RunCommand acCmdFitToWindow

Egress:
Exit Function

ErrHandler:
Select Case Err.Number
Case 2501, 2046
'ignore
Case Else
ErrorMessages "fnOpenReport Function"
End Select
Resume Egress
End Function


--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com




  #13  
Old October 3rd, 2005, 07:32 PM
Rick Brandt
external usenet poster
 
Posts: n/a
Default

BruceM wrote:
If I have a command button for SendObject that opens an e-mail, and
if I then click the X at the top right of the e-mail without sending
it, I will get an Error 2501 (the Send Object action was canceled, or
something like that) message if I do not trap the error.


Then the code that calls SendObject has to trap for Error 2501 and ignore it
(or whatever else you want to do when that happens).

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


  #14  
Old October 3rd, 2005, 08:28 PM
BruceM
external usenet poster
 
Posts: n/a
Default

Thanks, that was what I figured. I have been doing that, but as I said, I
keep writing the same lines of error message and error handling code (msgbox
"Error #" ... etc.) for each event. I had hoped there was a way to avoid
the redundancy. I suspect not. It is not a big deal. I appreciate the
time you have put into the replies.

"Rick Brandt" wrote in message
. ..
BruceM wrote:
If I have a command button for SendObject that opens an e-mail, and
if I then click the X at the top right of the e-mail without sending
it, I will get an Error 2501 (the Send Object action was canceled, or
something like that) message if I do not trap the error.


Then the code that calls SendObject has to trap for Error 2501 and ignore
it
(or whatever else you want to do when that happens).

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com




  #15  
Old October 3rd, 2005, 10:04 PM
Rick Brandt
external usenet poster
 
Posts: n/a
Default

BruceM wrote:
Thanks, that was what I figured. I have been doing that, but as I
said, I keep writing the same lines of error message and error
handling code (msgbox "Error #" ... etc.) for each event. I had
hoped there was a way to avoid the redundancy. I suspect not. It is
not a big deal. I appreciate the time you have put into the replies.


Just as I did with functions for OpenForm and OpenReport you could create a
custom "wrapper function" that you use instead of SendObject. Within that
function you still use SendObject passing it all of the arguments that your
wrapper function uses and then you write the erorr handler in your custom
function that ignores error 2501.

Now you just use the wrapper function instead of SendObject directly and no
longer need to keep writing the error handler over and over again.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


  #16  
Old October 4th, 2005, 12:28 PM
BruceM
external usenet poster
 
Posts: n/a
Default

I can see where that technique could come in handy, and not just with
SendObject. I need to learn to look for opportunities to eliminate some of
the repetition that is inevitable with code. Thanks for pointing me in that
direction, and thanks too for all of your comments and suggestions on this
topic.

"Rick Brandt" wrote in message
...
BruceM wrote:
Thanks, that was what I figured. I have been doing that, but as I
said, I keep writing the same lines of error message and error
handling code (msgbox "Error #" ... etc.) for each event. I had
hoped there was a way to avoid the redundancy. I suspect not. It is
not a big deal. I appreciate the time you have put into the replies.


Just as I did with functions for OpenForm and OpenReport you could create
a
custom "wrapper function" that you use instead of SendObject. Within that
function you still use SendObject passing it all of the arguments that
your
wrapper function uses and then you write the erorr handler in your custom
function that ignores error 2501.

Now you just use the wrapper function instead of SendObject directly and
no
longer need to keep writing the error handler over and over again.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
x-post from previous question justin Using Forms 2 April 13th, 2005 09:48 PM
A report design question Al Setting Up & Running Reports 3 March 11th, 2005 09:41 PM
How to create a query with multiple answers to a question? Amit Running & Setting Up Queries 4 November 9th, 2004 04:52 PM
database design question e-mid Database Design 9 June 16th, 2004 09:42 PM
Word question regarding TOC (newbie question)... Herman Geerlings Formatting Long Documents 4 June 4th, 2004 03:12 PM


All times are GMT +1. The time now is 05:24 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.