error message

  • Thread starter Thread starter Mauro
  • Start date Start date
M

Mauro

Guest
hello there, I just finished a very easy project for the library in our elementary school. This is also my first and only project so far as I am not a programmer or anything. Therefor I do have a problem: I would like to change the error message that appears when a double record is input (I have a double key for "book code" and "class"). The message that appears now is the standard access one but I would like to make my own.... any hints? (please remember that I am a novice)
thnx for any help
 
I guess one way you could handle this would be to search your table for a record with the matching primary key. You would need to write this code in the BeforeUpdate Event on a data entry form. You couldn't use it in a datasheet.

dim rst as dao.recordset
dim db as dao.database
dim strSQL as string

set db=CurrentDb
strSQl="SELECT * FROM [TableName] WHERE [book code] = """ & me.controlName & """ and [class] = """ & me.controlname & """;"
set rst=db.openrecordset(strSQL, dbopensnapshot)

if rst.eof then
'No duplicate found. Do nothing
Else
'Duplicate found
msgbox$("Your error message")
endif

rst.close

'Destroy objects
set rst=nothing
set db=nothing

Hope this helps

Duane Barker

[This message has been edited by BarkerD (edited 10-19-2000).]
 
Duane, thanks for your reply... I didn't have time to try it before today but I did it and... I get an error message when I input the line
'strSQl="SELECT * FROM [TableName] WHERE [book code] = """ & me.controlName & """
and [class] = """ & me.controlname & """;" '
One more question: further in your reply you input 'msgbox$("Your error message")': can this be a form I've already made or is the format of a msgbox different?
Thanks for your kind reply
Mauro
 
Mauro,

In order to customise the standard error message you need to trap it. Have a try at doing this.

First of all enter a duplicate record so that you generate the error. In the standard error message there should be an error number, if not then click the help button on the error message and this will display the relevant help file which should tell you what the error number is.

Assuming you are using a form for your data entry, in your form's BeforeUpdate event try this code.

Dim strMessage as string
Dim strTitle as String
Dim Style as vbMsgBoxStyle

On Error GoTo ErrorHandler:

DoCmd acSave
Exit Sub

ErrorHandler:

If Err.Number = Enter the error number here Then
strMessage = "Enter your custom message inside these quotes"
strTitle = "Duplicate Record"
Style = vbCritical

Err.Description = strMessage
MsgBox(Err.Decsription,strTitle,style)
Cancel = True
End Sub

Have a go at this and see how you get on.
Good luck
Rob
 
Rob: I am sorry to say that I have tried your solution but I still get error messages which I don't understand (as I said I am not very familiar with access, I am just making this program for our elementary school as we don't have money for a real professional programmer).
do you think I could send you the zipped program (in access 2000) with a short explanation (as it is in Italian) and see for yourself the error I get? This of course if it is not too much trouble for you....
Mauro
 
Mauro,

No problem at all just get my e-mail address from my profile and I'll have a look for you.

Rob
 

Users who are viewing this thread

Back
Top Bottom