Error Handling

Chipcom

Registered User.
Local time
Today, 15:33
Joined
Apr 13, 2006
Messages
63
Hi

I need to Change the error messege to other text.
I use command that generates a new record and when I type a duplicate record I get the error :
Run-time error '2105':
You can't go to the specified record.
So I need to change this error text.
Can you please show me how?


Thanks
 
Create an error handler:

In the code that you have, at the top put:

Code:
On Error Go To err_handler

And at the bottom of your code, just after the end of your code but before the End Sub, put

Code:
Exit Sub

err_handler:
   If Err.Number = 2105 Then
      MsgBox "Put Your Message Here", vbExclamation, "Error"'
      Resume Next
   Else
      MsgBox Err.Description, "vbExclamation", "Error Number " & Err.Number
      Resume Next  
   End If
 
Hi

There is a problem , The program is generate the new record and not exits from the sub.


I need that when it comes to :
DoCmd.GoToRecord acDataForm, "Test", acNewRec

so if there is an error in this line it will show the error message and won't run this command but it will exit the sub
 
Just put it in the event (the red is just for reference to show you where, but use the code between the red):
Code:
[b][color=red]Private Sub Whatever_Click()[/color][/b]

On Error Go To err_handler

DoCmd.GoToRecord acDataForm, "Test", acNewRec

Exit Sub

err_handler:
   If Err.Number = 2105 Then
      MsgBox "Put Your Message Here", vbExclamation, "Error"'
      Resume Next
   Else
      MsgBox Err.Description, "vbExclamation", "Error Number " & Err.Number
      Resume Next  
   End If
[b][color=red]End Sub[/color][/b]
 
Your code is works But..............

HI Bob

Your code is works But..............

If you try to debug the code you will see that line:
DoCmd.GoToRecord acDataForm, "Test", acNewRec
runs first then it shows the error message and what I need is to stop that line from generates a new record - It is try to save the record :
I use a custom autonumber in the beforeupdate event and it increments even if I got the customized error message and I need to stop the customized autonumber in the beforeupdate event.
 
It would help, then, if you could post ALL of the APPLICABLE code. Also, it is good to share the WHOLE problem. For every post I answered exactly how it would work for what you asked. I think you need to remember that we can't read minds so you need to state the entire problem. But, if you aren't that experienced with Access I can understand that you wouldn't necessarily know what to ask. But, just a suggestion for the future, eh? :)
 
Last edited:
Here is the Code

Hi Bob

THis is the code:

When the user Press Enter Access opens a new record so it calls to beforeupdate sub and the same record is already found in the database it give customizes 2105 error and it have to stop calling the Next_Custom_Counter() .

The problem is that I don't know how to implement this.



PHP:
Public Sub Form_KeyPress(KeyAscii As Integer)
   Dim Erro As Integer
    '13=Carriage Return
     If KeyAscii = 13 Then
 On Error GoTo err_handler
      DoCmd.GoToRecord acDataForm, "TestTable", acNewRec   
        Exit Sub
err_handler:
    If Err.Number = 2105 Then
    ErrCheck = -1
      MsgBox "Duplicate Record", vbExclamation, "ERROR!!!" 
      
      Resume Next
     Else
      Resume Next
        End If
        End If
End Sub


PHP:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'Calls to Autonumber function
 'Calls Next_Custom_Counter

    ErrCheck = Form_KeyPress(k)
    If ErrCheck = 2105 Then
    Exit Sub
    ErrCheck = 0
    Else
     Me.Line.DefaultValue = Chr$(34) & Next_Custom_Counter() & Chr$(34)
      End If
      End Dub


Thanks
 

Users who are viewing this thread

Back
Top Bottom