G
Guest
I'm having a problem with trying to trap an error on a form that I've
created. I"m a "code newbie", so please keep that in mind.
Here's some background:
The database will contain records of certain diseases. The data will be
entered by county nurses, but before they enter all the data, I'd like to
check to make sure the data hasn't been entered already (sometimes there are
duplicates of the paperwork floating around). We tried putting a big "Save
Record" button on the form, but they were tabbing past it
Once they enter the info that goes in the primary key, I'd like it to try to
write the record to the database. That way, if it's a duplicate, it brings
up an error. My thought was to create an event on the AfterUpdate property
of the last field in the primary key, and write the record then
Here's what's throwing me--if the record adds successfully, it works fine.
If it's a duplicate, the code goes to the error handling section, but it
tells me that DataErr=0
and it never displays an error message.
Here's the code I've bashed together:
Private Sub Last_Name_AfterUpdate()
' checks for duplicate record
Dim DataErr As Integer
Dim Response As Integer
On Error GoTo Err_Add_Case_Click
DoCmd.GoToRecord , , acNewRec 'tries to add record to table
DoCmd.GoToRecord , , acPrevious 'returns to just added record
'to continue data entry
Exit_Last_Name_afterUpdate:
Exit Sub
Err_Add_Case_Click:
Select Case DataErr
Case 3022
MsgBox "This case is already in the system."
Me.Undo
Response = acDataErrContinue
Case Else
Response = acDataErrDisplay
End Select
Resume Exit_Last_Name_afterUpdate
End Sub
Thanks in advance for any help!
created. I"m a "code newbie", so please keep that in mind.
Here's some background:
The database will contain records of certain diseases. The data will be
entered by county nurses, but before they enter all the data, I'd like to
check to make sure the data hasn't been entered already (sometimes there are
duplicates of the paperwork floating around). We tried putting a big "Save
Record" button on the form, but they were tabbing past it
Once they enter the info that goes in the primary key, I'd like it to try to
write the record to the database. That way, if it's a duplicate, it brings
up an error. My thought was to create an event on the AfterUpdate property
of the last field in the primary key, and write the record then
Here's what's throwing me--if the record adds successfully, it works fine.
If it's a duplicate, the code goes to the error handling section, but it
tells me that DataErr=0
and it never displays an error message.
Here's the code I've bashed together:
Private Sub Last_Name_AfterUpdate()
' checks for duplicate record
Dim DataErr As Integer
Dim Response As Integer
On Error GoTo Err_Add_Case_Click
DoCmd.GoToRecord , , acNewRec 'tries to add record to table
DoCmd.GoToRecord , , acPrevious 'returns to just added record
'to continue data entry
Exit_Last_Name_afterUpdate:
Exit Sub
Err_Add_Case_Click:
Select Case DataErr
Case 3022
MsgBox "This case is already in the system."
Me.Undo
Response = acDataErrContinue
Case Else
Response = acDataErrDisplay
End Select
Resume Exit_Last_Name_afterUpdate
End Sub
Thanks in advance for any help!