I am using a form to add images to a table.
if there is an error 3022, I want to display a msg and give options to
proceed.
How can this be done?
if error 3022 - The changes you requested to the table were not successful
because they would create duplicate values in the index, primary key, or
relationship. Change the data in the field or fields that contain duplicate
data, remove the index, or redefine the index
then
Msg = "Warning Schedule Image for selected Report Date and Page was
previously entered." _
& vbCr & vbCr & "Yes, to be directed to the original record." _
& vbCr & "No, to delete current record." _
& vbCr & "Cancel, to make changes to current record."
ans = MsgBox(Msg, vbYesNoCancel)
If ans = vbNo Then
Me.Undo
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
DoCmd.GoToRecord , , acNewRec
MsgBox "Duplicate Deleted."
Exit Sub
ElseIf ans = vbYes Then
Me.Undo
'Go to record of original ID
rsc.FindFirst stLinkCriteria
Me.Bookmark = rsc.Bookmark
Exit Sub
End If

Signature
deb
Pieter Wijnen - 17 Sep 2007 20:48 GMT
Add Error Handling (Which you should do with all code)
Sub MySub()
On Error Goto Err_hdl
' Your Code
Ex_Code:
Exit Sub ' Function
Err_Hdl:
Select Case Err.Number
Case 3022:
'Your custom Err Handler Code
Case Else
MsgBox Err.Description,vbExlamation, "(" & Err.Number & ")" &
Err.Source
End Select
Resume Ex_Code
End Sub
HTH
Pieter
> I am using a form to add images to a table.
>
[quoted text clipped - 35 lines]
> Exit Sub
> End If
Tom Wickerath - 18 Sep 2007 10:12 GMT
Hi Deb,
To add a little to Pieter's answer, you can also trap for Error 3022 in the
Form_Err event procedure. I show an example of how to do this on page 13 of
my "Access Links.doc" Word document. You can download a zipped copy from here:
http://home.comcast.net/~tutorme2/samples/accesslinks.zip
Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
> I am using a form to add images to a table.
>
[quoted text clipped - 32 lines]
> Exit Sub
> End If