Question Create a custom "Error message box" (1 Viewer)

Steve_T

Registered User.
Local time
Today, 13:01
Joined
Feb 6, 2008
Messages
96
Hello all,
I am new to Access but with that i side i want to learn. I have created a Database that collates defects. The Primary key is called "DefectID" which takes its number from a defect form that is never repeated. Unfortunately ever so often a person will try and input the same defect twice, it goes without saying this would not be allowed as it is set it not allow duplicate entries. My question is, is there a way to create my own message box to pop up when this is attempted?
 

NigelShaw

Registered User.
Local time
Today, 13:01
Joined
Jan 11, 2008
Messages
1,573
Hi,

if there is an error when the second defect form is opened, then cant you error trap it? is it error trapped?

you can have your own customised error message with error trapping then, your program doesnt give you the debug option.

NS
 

Steve_T

Registered User.
Local time
Today, 13:01
Joined
Feb 6, 2008
Messages
96
Hi, Sorry i dont understand what you mean, as i said i am new to Access. When someone tries to input a already known DefectID a system generated message box pop's up and will not not allow you to save the record.
 

NigelShaw

Registered User.
Local time
Today, 13:01
Joined
Jan 11, 2008
Messages
1,573
Hi,

sorry, i slightly mi-understood your post. to be sure i am clear-

you have a table that collates defectID from another form. sometimes, a user tries to enter a defect that is already in the list and you get a message to say you cannot enter the record?

if so, you could use a Dlookup

Sub CheckDefectInList()
Dim intDefect As String

'Set your current form DefectID to enable check
intDefect = Forms![yourFormNameHere]![DefectID].Value

'look for an exisiting DefectID
If DLookup("DefectID", "YourTable", intDefect ) Then
MsgBox ("This Defect is already listed")
Exit Sub
Else
Exit Sub
End IF
End Sub

the DLookup reads

IF A DefectID in the Table = intDefect then show a message
otherwise, dont show a message.

you will need to change "Your Table" to the name of the table that holds the list of DefectID

NS
 

Steve_T

Registered User.
Local time
Today, 13:01
Joined
Feb 6, 2008
Messages
96
Hi all the Information including the DefectID is stored on the same table, your code seems to be what i need.
Just one more question, where would i store the code, am i right to assume it is "After Update" for the "DefectID" Field?
 

NigelShaw

Registered User.
Local time
Today, 13:01
Joined
Jan 11, 2008
Messages
1,573
Hi all the Information including the DefectID is stored on the same table, your code seems to be what i need.
Just one more question, where would i store the code, am i right to assume it is "After Update" for the "DefectID" Field?

Hi Steve,

it all depends on what you want to happen. if the user has to press an apply button to initially attempt to create the record, i would put the code on the OnClick of the button-

Sub ApplyButton_OnClick()
Dim intDefect As String

'Set your current form DefectID to enable check
intDefect = Forms![yourFormNameHere]![DefectID].Value

'look for an exisiting DefectID
If DLookup("DefectID", "YourTable", intDefect ) Then
MsgBox ("This Defect is already listed")
Exit Sub
Else

'YOUR CODE HERE TO ENTER THE DEFECTID RECORD

Exit Sub
End IF
End Sub

regs,

Nigel
 

Steve_T

Registered User.
Local time
Today, 13:01
Joined
Feb 6, 2008
Messages
96
Thanks for your help,
i have placed the else code in and it works fine
 

Users who are viewing this thread

Top Bottom