Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 04-17-2019, 04:45 AM   #1
Access_Help
Newly Registered User
 
Join Date: Feb 2005
Posts: 87
Thanks: 29
Thanked 0 Times in 0 Posts
Access_Help is on a distinguished road
Customising Error 3022

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

__________________
Not an Access Programmer
But want to be one day....
Access_Help is offline   Reply With Quote
Old 04-17-2019, 04:50 AM   #2
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 8,875
Thanks: 105
Thanked 2,378 Times in 2,186 Posts
isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all
Re: Customising Error 3022

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
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 04-17-2019, 07:06 AM   #3
gemma-the-husky
Super Moderator
 
gemma-the-husky's Avatar
 
Join Date: Sep 2006
Location: UK
Posts: 13,501
Thanks: 54
Thanked 958 Times in 926 Posts
gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all gemma-the-husky is a name known to all
Re: Customising Error 3022

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
    on error resume next
    .AddNew
    ![ExamAssign] = [tbl_assignSessions Subform].[Form]![ExamAssign]
    ![Session] = List41.Column(3, varItm)
    ![Initials] = List41.Column(0, varItm)
    .Update
     if err>0 then
         If Err.Number = 3022 Then
               MsgBox "That combination already exists, try again"
         Else
              MsgBox Err.Num & " " & Err.Description
        end if 
    End If
  End With

__________________
Dave (Male!)
Gemma was my dog

if a poster helps you, please click the scales at the top right of this posting, or use the thanks button alongside.
gemma-the-husky is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Question Customising Default Error Messages Ezz General 7 01-22-2010 04:25 AM
Error 3022 danny123 Queries 7 02-14-2007 08:36 AM
MDB error 3022 Macbeth General 4 03-23-2005 10:13 AM
[SOLVED] Any experts on customising error messages? Jonny18 General 2 02-07-2003 01:44 PM
Customising Jet Error messages not_rich_yet Forms 6 03-31-2002 06:04 AM




All times are GMT -8. The time now is 12:30 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World