Hi
I have a field in a subform that contains a primary key. When entering duplicate value, I want to be able to display a custom message and display the original entry value. So far I've modified some code from msdn to get the following
This works fine on a single form, but how can I change it to work to bring both the mainform and subform which is linked master/child.
Any help would be appreciated.
Thanks
I have a field in a subform that contains a primary key. When entering duplicate value, I want to be able to display a custom message and display the original entry value. So far I've modified some code from msdn to get the following
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Dim str As String
Dim ID As String
Dim rs As DAO.Recordset
'MsgBox "DataErr: " & DataErr
If DataErr = 3022 Then
'Duplicate record:
ID = CStr(Study_Number.Value)
str = "It appears that EmployeeID " & ID _
& "already exists in the table." & vbCrLf & vbCrLf _
& "Would you like to view the existing record?"
If MsgBox(str, vbYesNo) = vbYes Then
Me.Undo 'Undo changes
Set rs = Me.RecordsetClone
rs.FindFirst ("Study_Number" = ID)
Me.Bookmark = rs.Bookmark
End If
End If
'Continue without displaying
'default error message:
Response = acDataErrContinue
End Sub
This works fine on a single form, but how can I change it to work to bring both the mainform and subform which is linked master/child.
Any help would be appreciated.
Thanks