How to change the default message created by null in primary key

  • Thread starter Thread starter GA
  • Start date Start date
G

GA

Hello,
I've been asked to provide a more informative message than "Index or
primary key cannot contain a null value" when a control is left empty.

Everything I've tried up to now has failed.

This relates to a combobox control on a subform which together with
the record id on the main form forms the primary key for the subform
record.

I set the combo to be first in the tab index and thought that if it
lost focus whilst still null I could generate my own dialogue message
before the system one 'kicked in' but I can't get this to work.

What's the best way to achieve this please?

Thanks GA
 
Hello,
I've been asked to provide a more informative message than "Index or
primary key cannot contain a null value" when a control is left empty.

Everything I've tried up to now has failed.

This relates to a combobox control on a subform which together with
the record id on the main form forms the primary key for the subform
record.

I set the combo to be first in the tab index and thought that if it
lost focus whilst still null I could generate my own dialogue message
before the system one 'kicked in' but I can't get this to work.

What's the best way to achieve this please?

Thanks GA

Here's how you can find the correct error and show your own message
for any of the form level errors.

First code the Form's Error event:

MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message

Then open the form and intentionally make that error.

The message box will display the error number and the default error
message.

Next, go back to the error event and change that code to:

If DataErr = XXXX Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Please enter data in all required fields."
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.
 
Back
Top