8 Replies - 864 Views - Last Post: 17 January 2017 - 03:57 AM

#1 Bonekit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 09-May 16

Access 2016 Form_Error isnīt working

Posted 16 January 2017 - 05:01 AM

Hello Folks,

I have a problem with Form_Error.
Private Sub Form_Error(DataErr As Integer, Response As Integer)
    'Declaration
    Const conDeleteError = 2046
    Const conAddNewRecordError = 2105
    Const conUpdateError = 3314
    Dim strMsg As String
    
    'Check and Message
    Select Case DataErr
        Case conDeleteError
            MsgBox "You canīt delete a blank record!", vbCritical, "Not Possible"
            Exit Sub
        Case conAddNewRecordError
            MsgBox "A new Record is open, you canīt open another one!", vbCritical, "Not Possible"
            Exit Sub
        Case conUpdateError
            MsgBox "Please Enter First- and Last name before you update!", vbCritical, "Not Possible"
            Exit Sub
    End Select
End Sub



I get still a default access message for error code: 2046, 2105, 3314.
Why? I supposed a problem with my On Error GoTo Function for the objects, i set the function off, but still the same problem.

I hope someone can help me.

Regards,
Tobias

Is This A Good Question/Topic? 0
  • +

Replies To: Access 2016 Form_Error isnīt working

#2 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6340
  • View blog
  • Posts: 25,573
  • Joined: 12-December 12

Re: Access 2016 Form_Error isnīt working

Posted 16 January 2017 - 05:11 AM

You haven't set the Response to acDataErrContinue so the default error message is still displayed.

docs
Was This Post Helpful? 1
  • +
  • -

#3 maceysoftware  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 348
  • View blog
  • Posts: 1,491
  • Joined: 07-September 13

Re: Access 2016 Form_Error isnīt working

Posted 16 January 2017 - 05:19 AM

From the looks of things as I have no direct experience with this, you need to set the response to a const called 'acDataErrContinue' which by the looks of things basically means you have handled the error message access doesn't need to show theirs.

I found this page after a really quick google based on what you have said in your thread, which is where I am drawing my conclusion from.

Looks like Andrew and myself did the same google search on that one!
Was This Post Helpful? 1
  • +
  • -

#4 Bonekit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 09-May 16

Re: Access 2016 Form_Error isnīt working

Posted 16 January 2017 - 09:58 AM

Hey Guys,

So, i forgot the part with response.
But still the same problem.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6340
  • View blog
  • Posts: 25,573
  • Joined: 12-December 12

Re: Access 2016 Form_Error isnīt working

Posted 16 January 2017 - 10:09 AM

Post your revised code.

You mentioned use of On Error GoTo, how is this involved? If the problem arises outside of the code you are posting then you need to provide more information (and probably more code).
Was This Post Helpful? 0
  • +
  • -

#6 Bonekit  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 09-May 16

Re: Access 2016 Form_Error isnīt working

Posted 17 January 2017 - 12:06 AM

Option Compare Database
Option Explicit

Private Sub btnAddPerson_Click()
    'Error_Handler
    On Error GoTo Err_Handler
    
    'Add Macro
    DoCmd.GoToRecord , , acNewRec
    Exit Sub
    
Err_Handler:
    Call MySubRoutine
End Sub

Private Sub btnDeletePerson_Click()
    'Error_Handler
    On Error GoTo Err_Handler
    
    'Delete Macro
    If MsgBox("Are you sure you want to Delete Person: " & perNameShow & "?", vbQuestion + vbYesNo, "Delete Person") = vbYes Then
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.SetWarnings True
        Exit Sub
    Else
        Exit Sub
    End If
    
Err_Handler:
    Call MySubRoutine
End Sub

Private Sub btnEditPerson_Click()
    'Error_Handler
    On Error GoTo Err_Handler

    'Refresh Record after Editing
    DoCmd.RefreshRecord
    Exit Sub
    
Err_Handler:
    Call MySubRoutine
End Sub

Private Sub btnExitFormPeople_Click()
    'Exit Form "People"
    DoCmd.Close
End Sub

Private Sub btnNextRecord_Click()
    'Error_Handler
    On Error Resume Next
    
    'GoTo Next Macro
    DoCmd.GoToRecord , , acNext
End Sub

Private Sub btnPreRecord_Click()
    'Error_Handler
    On Error Resume Next
    
    'GoTo Previous Macro
    DoCmd.GoToRecord , , acPrevious
End Sub

Private Sub Form_Error(DataErr As Integer, Response As Integer)
    'Declaration
    Const conDeleteError = 2046
    Const conAddNewRecordError = 2105
    Const conUpdateError = 3314
    Dim strMsg As String
    
    'Check and Message
    Select Case DataErr
        Case conDeleteError
            MsgBox "You canīt delete a blank record!", vbCritical, "Not Possible"
            Exit Sub
        Case conAddNewRecordError
            MsgBox "A new Record is open, you canīt open another one!", vbCritical, "Not Possible"
            Exit Sub
        Case conUpdateError
            MsgBox "Please Enter First- and Last name before you update!", vbCritical, "Not Possible"
            Exit Sub
    End Select
End Sub



Here is my Subroutine
Option Compare Database
Option Explicit

Public Sub MySubRoutine()
    'Error Handler
    MsgBox "Error Occured!" & vbCr & vbCr & "Error Number is: " & Err.Number & vbCr & "Error Description:" & vbCr & Err.Description & "."

End Sub


Was This Post Helpful? 0
  • +
  • -

#7 maceysoftware  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 348
  • View blog
  • Posts: 1,491
  • Joined: 07-September 13

Re: Access 2016 Form_Error isnīt working

Posted 17 January 2017 - 12:26 AM

Your Form_Error is still missing the Response being set.

Private Sub Form_Error(DataErr As Integer, Response As Integer)
    'Declaration
    Const conDeleteError = 2046
    Const conAddNewRecordError = 2105
    Const conUpdateError = 3314
    Dim strMsg As String
    
    'Check and Message
    Select Case DataErr
        Case conDeleteError
            MsgBox "You canīt delete a blank record!", vbCritical, "Not Possible"
            Exit Sub
        Case conAddNewRecordError
            MsgBox "A new Record is open, you canīt open another one!", vbCritical, "Not Possible"
            Exit Sub
        Case conUpdateError
            MsgBox "Please Enter First- and Last name before you update!", vbCritical, "Not Possible"
            Exit Sub
    End Select
End Sub



Can you explain what your doing? as in how your getting the issue? are you inserting? Updating? Deleting? is it all of the already mentioned?

It is also worth noting that Form_Error only traps certain types of errors, one of the types of error messages are ADO error messages. I would most likely say that the application is still calling Form_Error even through you have handled it in the sub routine because its one of the types of error messages that get sent to Form_Error. Seeing as your code still does not include it i would recommend what Andrew and myself first mentioned.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6340
  • View blog
  • Posts: 25,573
  • Joined: 12-December 12

Re: Access 2016 Form_Error isnīt working

Posted 17 January 2017 - 02:47 AM

From the linked page:

Quote

Remarks

This includes Microsoft Access database engine errors, but not run-time errors in Visual Basic or errors from ADO.

Was This Post Helpful? 1
  • +
  • -

#9 maceysoftware  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 348
  • View blog
  • Posts: 1,491
  • Joined: 07-September 13

Re: Access 2016 Form_Error isnīt working

Posted 17 January 2017 - 03:57 AM

Good spot Andrew, I read that snippet but got it muddled up, going to blame that one on only just having my first cup of tea of the day!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1