custom message

xcao

Registered User.
Local time
Today, 09:27
Joined
Nov 25, 2003
Messages
40
I have a command button which generates password and
append to userpass table.

Because one user can only have one password, I set
username as primary key in the table.

So when somebody click generate password button, if the
password already exists, it will show the message:

cannot append the table...due to validation rule
violation.

This is fine, but I want to custom the message a little
bit like: this user already have a password.
instead of using the Access original message?

How can I do that?

Thanks
 
Maybe if you find out the error # associated with that error, you can catch the error and display your custom message box. I am not so great at doing this but I am sure it's possible
 
customize message

Actually it is not an error message. It seems it is an informational message.

It happens whenever there is a primary key violation.

So although I have error handling code, but this is not an error.

Any suggestions for avoiding this message but using my own message?

Thanks
 
Here's a link to a post with some simple code that can display the error number and message for you. You can then customize it for your situation: Duplicates error message
 
On your form, look for the OnError event.

Open the code for that event and put the line:

MsgBox DataErr


Run the form and you'll get a message box that tells you the error number.

So, return to the code and delete the MsgBox statement and - for example, if the number returned was 2113 then:

Code:
If DataErr = 2113 Then
    MsgBox "This is where I display my custom error message.", vbExclamation, "My Custom Message"
    Response = acDataErrContinue
End If
 
Ann

Thanks all the help from everyone.

It helps a lot.
 
customize message

Actually it is not an error message. It seems it is an informational message.

It happens whenever there is a primary key violation.

So although I have error handling code, but this is not an error.

Any suggestions for avoiding this message but using my own message?

Thanks
 
FYI:

Actually it IS an error message and can be handled by an error handler. Even though it looks like it's, what you call, an
informational message
it is still an error message. An error has been generated that tells the user that they are trying to enter a value which would violate the primary key rule of no duplicates. Therefore, the user is in error and needs to correct the problem. You would catch the error within the code for the event that tried to update the table.
 
Thank you.

Yes, it is an error message.
It's like: Message1

microsoft access cannot append all the records in the append query.
Access set 0 field to Null due to a type conversion failure, and it didn't add 1 record to the table due to key violations,..........
Do you want to run the query anyway?
To ignore the error and run the query, click yes.

Yes , No

When I click no, it shows this message(message 2):

The error code is 2501
The error description is: the RunSQL action was canceled.
I can customize it as whatever I like.

BUt how about message 1, it seems I cannot avoid it.

Thanks.
 
xcao said:
BUt how about message 1, it seems I cannot avoid it.

That's a warning; not an error.

You need to:

Code:
DoCmd.SetWarnings False
    [i]your code here[/i]
DoCmd.SetWarnings True
 
Try this, it's the same as Mile-O-Phile's but uses cases. Works for me.
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)

Select Case DataErr
    Case 3022
        MsgBox "Your Message"
        Response = acDataErrContinue
     
    Case 2237, 3162, 3314
        MsgBox "Your Message"
        Response = acDataErrContinue

    Case Else
        Response = acDataErrDisplay
End Select

End Sub
 
Last edited:
I am going to reignite this thread as my problem is pretty much identical to this but try as I might I can not fix it using the advice here. I need it really spelt out for me. Pretty much a total noob and making lots of mistakes as I go along.

So the problem I have is this. I am using a a command button to run an append query and it is all working fine except when I end up with a key violation. I want to customise the messages the user sees so they don't freak out. The logical thing I decide is to intercept these message boxes and put my own stuff in there. So I come on here and notice the exact same discussion. Bingo! However, I can't make it work. I am a dumb*ss.

I can not intercept error 10506: You are about to append | row(s) or 10510 which is: Microsoft Access can't append all the records in the append query. The only reason I have these numbers is because I got them from a website which lists most of the MS Access error codes. If you want to know I HAVE tried caturing the numbers from within the code below but it does not give me the numbers for the messages just 3059 "operation cancelled by user" which is no help at all.

My questions:

1) Are 10506 & 10510 "error" messages to be handled with "DataErr" expressions or are they something else? If they are "something else" what is the relevant expression to catch them

2) Where does the, lets call it "message handling" code sit in the code builder? Does it go within my coding for the command button or does it sit as a private sub somewhere else? If it is "somewhere else" where is it and how do i direct my "warning / error / whatever it is" to go there?

Here is my code apologies if it is rubbish.

Private Sub B_ADDPOSTPANELMAIN_Click()
On Error GoTo Err_B_ADDPOSTPANELMAIN_Click

Dim stSQL As String
Dim stDocName As String
Dim stLinkCriteria As String


stSQL = "INSERT INTO T_POSTPANEL ( [CLIENT ID], [Funding Group], [PPID])VALUES (Forms!F_MAIN![CLIENT ID], Forms!F_MAIN![Funding Group], (Forms!F_MAIN![CLIENT ID] & Forms!F_MAIN![Funding Group]));"

DoCmd.RunSQL stSQL
stDocName = "F_POSTPANEL"
stLinkCriteria = "[CLIENT ID]=" & Me![CLIENT ID]
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.NAME

Exit_B_ADDPOSTPANELMAIN_Click:
Exit Sub
Err_B_ADDPOSTPANELMAIN_Click:
MsgBox Err.Description
Resume Exit_B_ADDPOSTPANELMAIN_Click
End Sub


Thanks - this forum has been a massive help to me in constructing my DB thus far.

Cheers

Scott
 
Last edited:

Users who are viewing this thread

Back
Top Bottom