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

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 02-12-2011, 05:14 AM   #1
uniboy
Newly Registered User
 
Join Date: Feb 2011
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
uniboy is on a distinguished road
Next button code question...

Iv got Next and Previous buttons, both of which work. When I get to the start of the record set my error message appears which is great. but when i get to the end of the record set, my error message does not appear. Here is my code, im sure its just a little thing i need to change but I just cant find it:

'This goes to the next record
Private Sub cmdNext_Click()
On Error GoTo Err_bNext_Click

If Me.Dirty Then
MsgBox "Please save the changes to the record." & vbCrLf & vbLf & "You can not advance from this record until you Save the changes made, or Delete the record.", vbExclamation, "Save Required"
ElseIf Me.CurrentRecord < Me.RecordsetClone.RecordCount Then
DoCmd.GoToRecord , , acNext
End If

Exit_bNext_Click:
Exit Sub

Err_bNext_Click:
MsgBox "Please click Previous to view previous records.", vbExclamation, "End of Record Set"
Resume Exit_bNext_Click
End Sub


'This goes to the previous code
Private Sub cmdPrevious_Click()

On Error GoTo Err_bPrevious_Click

If Me.Dirty Then
MsgBox "Please save the changes to the record." & vbCrLf & vbLf & "You can not advance from this record until you Save the changes made, Delete the record or Undo the changes made.", vbExclamation, "Save Required"
ElseIf Me.CurrentRecord <= Me.RecordsetClone.RecordCount Then
DoCmd.GoToRecord , , acPrevious
End If

Exit_bPrevious_Click:
Exit Sub

Err_bPrevious_Click:
MsgBox "Please click Next to view more records.", vbExclamation, "Start of Record Set"
Resume Exit_bPrevious_Click

End Sub

uniboy is offline   Reply With Quote
Old 02-12-2011, 06:50 AM   #2
RuralGuy
AWF VIP
 
RuralGuy's Avatar
 
Join Date: Jul 2005
Location: @ 8300' in the Colorado Rockies
Posts: 13,820
Thanks: 7
Thanked 311 Times in 301 Posts
RuralGuy is just really nice RuralGuy is just really nice RuralGuy is just really nice RuralGuy is just really nice RuralGuy is just really nice
Re: Next button code question...

The Recordset.RecordCount is *not* guaranteed accurate until after you have gone to the last record in the Recordset. (Movelast)
__________________
(RG for short) aka Allan Bunch Previous MS Access MVP acXP, ac07, ac10, ac13 - WinXP Pro, Win7 Pro, Win10 Pro
Please post back to this Forum so all may benefit.
Teaching is not filling a bucket but lighting a fire.
RuralGuy is offline   Reply With Quote
Old 02-12-2011, 06:53 AM   #3
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Next button code question...

Are you talking about the error message in the error handler or your verification msgbox?

vbaInet is offline   Reply With Quote
Old 02-12-2011, 07:15 AM   #4
uniboy
Newly Registered User
 
Join Date: Feb 2011
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
uniboy is on a distinguished road
Re: Next button code question...

im talking about my error message, which is:

MsgBox "Please click Previous to view previous records.", vbExclamation, "End of Record Set"

I want that message to appear when I try and click Next on the last record.

any ideas mate?
uniboy is offline   Reply With Quote
Old 02-12-2011, 07:49 AM   #5
DCrake
Remembered
 
DCrake's Avatar
 
Join Date: Jun 2005
Location: Burnley, Lancashire
Posts: 8,634
Thanks: 8
Thanked 325 Times in 208 Posts
DCrake is a glorious beacon of light DCrake is a glorious beacon of light DCrake is a glorious beacon of light DCrake is a glorious beacon of light DCrake is a glorious beacon of light DCrake is a glorious beacon of light
Send a message via Skype™ to DCrake
Re: Next button code question...

There are only 4 possible outcomes

1. EOF = True + BOF = True - No records
2. EOF = True + BOF = False - Last Record
3 .EOF = False +BOF = True - First Record
4. EOF = False + BOF = False - Somewhere inbetween

1 Cannot go backward or forward
2 Backwards only
3 Forwards only
4 forwards and backwards

Each time you click on any of the button you need to test for the matching condition and respond accordingly.
__________________
David Crake


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
The Home of Simple Software Solutions.

O/S Windows XP (SP3) & Windows 7 64bit
Access 2003 (version 11.0)
Access 2007 (version 12.0)

Remember when posting sample databases you will get a better response if it is pre Access 2007 - not all people have it installed.
DCrake is offline   Reply With Quote
Old 02-12-2011, 02:19 PM   #6
vbaInet
AWF VIP
 
Join Date: Jan 2010
Location: U.K.
Posts: 26,374
Thanks: 0
Thanked 2,423 Times in 2,389 Posts
vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all vbaInet is a name known to all
Re: Next button code question...

You will find that the BOF and EOF properties don't work on a form's recordset.

I don't see why that message will not appear if there are unsaved changes. I suspect that somewhere in your code you are forcing the record to be saved.

vbaInet is offline   Reply With Quote
Reply

Tags
button , error , next record

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add button and code from VBA Thomas256 Modules & VBA 3 05-08-2009 11:42 PM
making a button with code by clicking a button tomro1 Modules & VBA 1 02-15-2007 10:15 PM
Run Code within code.. Newbie Question ezykiwi Modules & VBA 4 10-05-2006 07:06 AM
help with button code dgb Modules & VBA 2 04-29-2002 09:02 AM
Button code Anders Forms 1 04-20-2001 05:16 AM




All times are GMT -8. The time now is 04:20 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