Customising Error 3022 (1 Viewer)

Access_Help

Registered User.
Local time
Today, 06:16
Joined
Feb 12, 2005
Messages
136
Can someone please help me place the customised 3022 message into this code as it is still defaulting to the original msg

Code:
Dim rst As DAO.Recordset
Dim varItm As Variant

Set rst = CurrentDb.OpenRecordset("tbl_assignSessions", dbOpenDynaset)

  
For Each varItm In List41.ItemsSelected
  With rst
    .AddNew
    ![ExamAssign] = [tbl_assignSessions Subform].[Form]![ExamAssign]
    ![Session] = List41.Column(3, varItm)
    ![Initials] = List41.Column(0, varItm)
    .Update
    If Err.Number = 3022 Then
    MsgBox "That combination already exists, try again"
    Else
        MsgBox Err.Num & " " & Err.Description
    
    End If
  End With
Next varItm

rst.Close
Set rst = Nothing
 Forms![tbl_Exams]![tbl_assignSessions Subform].Requery
End Sub
 

isladogs

MVP / VIP
Local time
Today, 14:16
Joined
Jan 14, 2017
Messages
18,211
Move your error handling to its own section

Code:
Private Sub ProcName()

On Error GoTo Err_Handler
 
'your code goes here
      
Exit_Handler:
    Exit Sub

Err_Handler:
    If Err.Number = 3022 Then
        MsgBox "That combination already exists, try again"
    Else
        MsgBox "Error " & Err.Number & " " & Err.Description
    End If
        
    Resume Exit_Handler

End Sub
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 14:16
Joined
Sep 12, 2006
Messages
15,650
Also, I saw this sort of construct the other day which seemed to do the job.
You may need to reset the error-handler at a suiaable point.

Code:
  With rst
    [COLOR="DarkRed"]on error resume next[/COLOR]
    .AddNew
    ![ExamAssign] = [tbl_assignSessions Subform].[Form]![ExamAssign]
    ![Session] = List41.Column(3, varItm)
    ![Initials] = List41.Column(0, varItm)
    .Update
    [COLOR="Red"] if err>0 then[/COLOR]
         If Err.Number = 3022 Then
               MsgBox "That combination already exists, try again"
         Else
              MsgBox Err.Num & " " & Err.Description
        end if 
    [COLOR="red"]End If[/COLOR]
  End With
 

Users who are viewing this thread

Top Bottom