supress messages

B

blackcat

I'd like to supress a system message ie 'unable to copy record due to
duplicate unique key' or words to that effect, and replace it with my own
message telling the user to click ok and return to existing form. I have
button on a form as an event prodcedure, which opens the query which copies
the record to another table and would like this message placed on this event
procedure. Can this be done
 
J

Jeff Boyce

While it would be possible, why bother?

(That wasn't facetious.) Wouldn't it be even better "customer service" if
there was no message at all? That way, the user wouldn't need to click an
OK in order for the process to run.

If you turn off the warnings before running the query, you/user wouldn't be
notified that a duplicate key blocked the copy. If you don't turn the
warnings back on after the query, you will never know when Access is
failing. (That WAS facetious.)

WARNING: turn the warnings back on!

If you are working in code behind the button, you can use the
DoCmd.SetWarnings
command. If you are working with a macro, you can select the SetWarnings
command there.

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/
 
B

blackcat

i understand what you're saying and yes, i do need a message there, however,
the system message isn't very user friendly - not for some of our users
anyway, so i just wanted to turn this one off and replace it with a message
of my own which is more user friendly, does that make sense?
 
C

Corey-g via AccessMonster.com

I think this is a good place for error trapping. In your event procedure
(code) use the "On Error ..." code. This way you can do a number of things -
like writing the error code, message, user, time, etc... to a error log table
/ file, send user's messages that are much more user friendly, etc...

HTH,

Corey
i understand what you're saying and yes, i do need a message there, however,
the system message isn't very user friendly - not for some of our users
anyway, so i just wanted to turn this one off and replace it with a message
of my own which is more user friendly, does that make sense?
While it would be possible, why bother?
[quoted text clipped - 22 lines]
 
B

blackcat

i have found this code which works on the 'On Error'
If DataErr = conduplicatekey then
Response = acdataerrcontinue
strmsg = "Each record must be unit"
msgbox strmsg
End If

where can i put it on the 'On Click' event procedure (button created)
amongst the following code to stop the system message which isn't very
friendly
Private Sub Command1825_Click()
On Error GoTo Err_Command1825_Click

Dim stDocName As String

stDocName = "signoff query"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_Command1825_Click:
Exit Sub

Err_Command1825_Click:
MsgBox Err.Description
Resume Exit_Command1825_Click

End Sub

many thanks


Corey-g via AccessMonster.com said:
I think this is a good place for error trapping. In your event procedure
(code) use the "On Error ..." code. This way you can do a number of things -
like writing the error code, message, user, time, etc... to a error log table
/ file, send user's messages that are much more user friendly, etc...

HTH,

Corey
i understand what you're saying and yes, i do need a message there, however,
the system message isn't very user friendly - not for some of our users
anyway, so i just wanted to turn this one off and replace it with a message
of my own which is more user friendly, does that make sense?
While it would be possible, why bother?
[quoted text clipped - 22 lines]
event
procedure. Can this be done
 
C

Corey-g via AccessMonster.com

I'm not sure if you figured this out yet or not...

The "IF DataErr" test you are doing should all be inside (below) the
"Err_Command1825_Click" label.

What happens is:
You have placed an "On Error" statement in the procedure - if there is an
error, it will go directly to the label.
You then have a "msgbox" command that will display the error description
(this is where you should change the message, or use the error number to
determine what message you would like to send to your users).
Otherwise, the msgbox just displays Access's description of the error - not
very friendly...

HTH,

Corey
 
B

blackcat

i'm sorry to be a pain but i just can't seam to get this to work, i still get
the system generated message and then the user friendly message that i have
created. would it be possible for you to type the code out for me exactly as
it should appear on the behind the 'on click' button. i know this is asking
a lot but i'm real stuck here!
 
B

blackcat

is the reason this isn't working is because i am trying to suppress the
system error massage which displays when i am trying to save a duplicate
record to a table based on a query - ie make table query? or am i just being
plan dumb?!
 
C

Corey-g via AccessMonster.com

Hi,

I'm not sure whatis hapening, as I don't have your application / code to see.
I think that you are seeing the unfriendly system error message from
somewhere other than the button click. If you want to handle the system
errors, you will need to have error handling in all of your code. Every
event (function / sub) can cause errors, and as such, need to have error
handling if you want to control what the user sees.

So, you have the code for the button click error handler, now you need to put
that into every procedure.
I place it in as part of every procedure like so:

Code:
' first the proc declaration
Private Function <<procedure_name>> (  )

On Error GoTo ErrorHandler   '  Here is the On Error statement that tells
Access that you want to do something if there is an error


FunctionExit:   ' Here is a label for the procedure exit - I place code that
MUST run before procedure ends
' like closing connections, releasing objects, de-referencing them, etc..
..

Exit Function

ErrorHandler:  '  Here is the label for the error handler
'  Here is where you write the code to handle the error
'  You can use Case statements, or what ever you wish, to decide how to
handle the error...

End Function


does that help?

Corey
 
B

blackcat

sorry, i'm still not getting this, looking at your code it looks like i'm
doing it right, but i still get the system error, please see my code below
and let me know where im going wrong - am i supposed to put some other code
somewhere else, in a module perhaps? sorry if i'm being a bit dense!

Private Sub Command1823_Click()
On Error GoTo Err_Command1823_Click

Dim stdocname As String
Dim response As Integer
Dim strmsg As String


stdocname = "signoff query"


DoCmd.OpenQuery stdocname, acNormal, acEdit




Exit_Command1823_Click:
Exit Sub
Err_Command1823_Click:

response = acDataErrContinue
strmsg = "Title Duplicated - Cannot save"
MsgBox strmsg
Resume Exit_Command1823_Click

End Sub


blackcat said:
yes, thanks for that, i'll give it a go

Corey-g via AccessMonster.com said:
Hi,

I'm not sure whatis hapening, as I don't have your application / code to see.
I think that you are seeing the unfriendly system error message from
somewhere other than the button click. If you want to handle the system
errors, you will need to have error handling in all of your code. Every
event (function / sub) can cause errors, and as such, need to have error
handling if you want to control what the user sees.

So, you have the code for the button click error handler, now you need to put
that into every procedure.
I place it in as part of every procedure like so:

Code:
' first the proc declaration
Private Function <<procedure_name>> (  )

On Error GoTo ErrorHandler   '  Here is the On Error statement that tells
Access that you want to do something if there is an error


FunctionExit:   ' Here is a label for the procedure exit - I place code that
MUST run before procedure ends
' like closing connections, releasing objects, de-referencing them, etc..
..

Exit Function

ErrorHandler:  '  Here is the label for the error handler
'  Here is where you write the code to handle the error
'  You can use Case statements, or what ever you wish, to decide how to
handle the error...

End Function


does that help?

Corey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top