A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Error handler help



 
 
Thread Tools Display Modes
  #1  
Old February 1st, 2010, 05:05 PM posted to microsoft.public.access.gettingstarted
SoggyCashew
external usenet poster
 
Posts: 108
Default Error handler help

Hello, I have a buttin on my form that takes me to the precious record. If I
go back to far it gives me a 2105 error. I Wanted to have a custom mesage and
an ok button but I cant get it to work. It still opens the error window
insted of a msg box. here is what I have

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious

Exit_MyErr:
Exit Sub
Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
End If
Resume Exit_MyErr

End Sub
--
Thanks,
Chad
  #2  
Old February 1st, 2010, 05:37 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Error handler help

Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
Resume Exit_MyErr
Else
Msgbox "Oops: you can't go any further!"
Resume Next
End If

End Sub

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"SoggyCashew" wrote in message
...
Hello, I have a buttin on my form that takes me to the precious record. If
I
go back to far it gives me a 2105 error. I Wanted to have a custom mesage
and
an ok button but I cant get it to work. It still opens the error window
insted of a msg box. here is what I have

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious

Exit_MyErr:
Exit Sub
Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
End If
Resume Exit_MyErr

End Sub
--
Thanks,
Chad



  #3  
Old February 1st, 2010, 06:27 PM posted to microsoft.public.access.gettingstarted
Dorian
external usenet poster
 
Posts: 542
Default Error handler help

You should disable the PREV button when at the top, and the NEXT button when
at the bottom, so this can never occur.
There are standard techniques for doing this, google them.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".


"SoggyCashew" wrote:

Hello, I have a buttin on my form that takes me to the precious record. If I
go back to far it gives me a 2105 error. I Wanted to have a custom mesage and
an ok button but I cant get it to work. It still opens the error window
insted of a msg box. here is what I have

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious

Exit_MyErr:
Exit Sub
Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
End If
Resume Exit_MyErr

End Sub
--
Thanks,
Chad

  #4  
Old February 1st, 2010, 07:30 PM posted to microsoft.public.access.gettingstarted
SoggyCashew
external usenet poster
 
Posts: 108
Default Error handler help

Douglas, Im getting an error: label not defined? Also, Dorianthak I hae tried
to google your answer to my question but with no luck.

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious

Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
Resume Exit_MyErr
Else
MsgBox "Oops: you can't go any further!"
Resume Next
End If

End Sub



--
Thanks,
Chad


"Douglas J. Steele" wrote:

Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
Resume Exit_MyErr
Else
Msgbox "Oops: you can't go any further!"
Resume Next
End If

End Sub

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"SoggyCashew" wrote in message
...
Hello, I have a buttin on my form that takes me to the precious record. If
I
go back to far it gives me a 2105 error. I Wanted to have a custom mesage
and
an ok button but I cant get it to work. It still opens the error window
insted of a msg box. here is what I have

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious

Exit_MyErr:
Exit Sub
Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
End If
Resume Exit_MyErr

End Sub
--
Thanks,
Chad



.

  #5  
Old February 1st, 2010, 08:55 PM posted to microsoft.public.access.gettingstarted
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default Error handler help

You forgot to include

Exit_MyErr:
Exit Sub

The entire thing should be

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious


Exit_MyErr:
Exit Sub

Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
Resume Exit_MyErr
Else
MsgBox "Oops: you can't go any further!"
Resume Next
End If

End Sub




--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"SoggyCashew" wrote in message
...
Douglas, Im getting an error: label not defined? Also, Dorianthak I hae
tried
to google your answer to my question but with no luck.

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious

Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
Resume Exit_MyErr
Else
MsgBox "Oops: you can't go any further!"
Resume Next
End If

End Sub



--
Thanks,
Chad


"Douglas J. Steele" wrote:

Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
Resume Exit_MyErr
Else
Msgbox "Oops: you can't go any further!"
Resume Next
End If

End Sub

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"SoggyCashew" wrote in message
...
Hello, I have a buttin on my form that takes me to the precious record.
If
I
go back to far it gives me a 2105 error. I Wanted to have a custom
mesage
and
an ok button but I cant get it to work. It still opens the error
window
insted of a msg box. here is what I have

Private Sub cmdPrevious_Click()
On Error GoTo Err_MyErr

DoCmd.GoToRecord , , acPrevious

Exit_MyErr:
Exit Sub
Err_MyErr:
If Err.Number 2105 Then
MsgBox "Custom Test Message"
End If
Resume Exit_MyErr

End Sub
--
Thanks,
Chad



.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:24 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.