This one has been bugging me for a while, and I can't find a solution to get round it.
The error message is:
Run-time 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 to permit duplicate entries and try again.
Where this occurs:
I have a form with a BLOB file upload section. The code for this is:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdSave_Click()
- Dim db As dao.Database
- Dim rst As dao.Recordset
- Dim strFileName As String
- Set db = CurrentDb
- Set rst = db.OpenRecordset("ResultsScreenshots")
- 'Check a file path was entered.
- If getFileName(txtPath.Value) <> "" Then 'See modGlobals for getFileName function.
- 'Next check that the file exists.
- If fileExists(txtPath.Value, getFileName(txtPath.Value)) Then 'See modGlobals for fileExists function.
- rst.AddNew 'Prepare recordset for a new record.
- If ReadBLOB(txtPath.Value, rst, "Screenshot") = 1 Then 'Stores the binary data see modBlob for ReadBLOB function.
- rst!FileName = getFileName(txtPath.Value) 'Stores the filename.
- rst!FileExtension = getFileExtension(txtPath.Value) 'Stores the file extension.
- rst!UploadedBy = GUsername 'Stores the user who uploaded the file.
- rst.Update 'Update the record.
- MsgBox "File uploaded.", vbInformation 'Confirm to the user that the file was uploaded.
Expand|Select|Wrap|Line Numbers
- rst.Update 'Update the record.
Currently the only way to upload another file is to shut down Access and re-open it again, though this is because it compacts on close and the deleted files actually ARE deleted, so the ID number becomes available again (as it is the next number that follows the Maximum ID actually in use).
Can anyone offer any solutions to either fixing, trapping or bypassing this error?
Many thanks!