confused with navigation code

Ziggy1

Registered User.
Local time
Today, 22:29
Joined
Feb 6, 2002
Messages
462
when I use this code, the navigation buttons get disabled, but if I try to Debug, it gets really confusing...I get mixed results...using "F5" and "F8"...sometimes it disables the "next" and other times it doesn't.

all I'm trying to do is eliminate the message saying you can't go to the specified record.


http://www.access-programmers.co.uk/forums/showthread.php?s=&threadid=44199

Code:
Private Sub Form_Current()


'Command12 = cmdPrev
'Command11 = cmdNext

  'Disable navigation buttons on end and beginning
If Me.RecordsetClone.RecordCount = 1 Then 'There is only one record

'cmdfirst.Enabled = False
'cmdlast.Enabled = False
Command12.Enabled = False
Command11.Enabled = False

ElseIf Me.RecordsetClone.RecordCount = Me.CurrentRecord Then 'You're at the last record
Command12.Enabled = True
Command11.Enabled = False
'cmdlast.Enabled = False
'cmdfirst.Enabled = True

ElseIf Me.CurrentRecord = 1 Then 'You're at the first record
Command12.Enabled = False
'cmdfirst.Enabled = False
Command11.Enabled = True
'cmdlast.Enabled = True

Else 'Your somewhere in between
Command12.Enabled = True
Command11.Enabled = True
'cmdfirst.Enabled = True
'cmdlast.Enabled = True

End If

End Sub

Edit:

I threw this in, and it tricks the code, but will probably fail if there is only one record

Private Sub Form_Open(Cancel As Integer)
Me.Recordset.MoveNext
End Sub
 
Last edited:
Dont know if this will help, but do you have the following anywhere to get correct count?

Me.RecordsetClone.movelast
 
Thanks for the Reply JoanneJames

as far as I know this: Me.RecordsetClone.RecordCount gets the Count.


I changed this line to <= 1


Code:
If Me.RecordsetClone.RecordCount <= 1 Then 'There is only one record



And put this in the open even, probably very "Hackish" of me but it seems to be working, I even tested with all records deleted.


Code:
Private Sub Form_Open(Cancel As Integer)

If Me.Recordset.RecordCount = 1 Then
Me.Recordset.MoveNext
Me.Recordset.MoveFirst
End If

End Sub
 
Thanks for the Reply JoanneJames

as far as I know this: Me.RecordsetClone.RecordCount gets the Count.
Well, it doesn't. A form's recordset.RecordCount and RecordsetClone.RecordCount will not be valid until it makes an appearance at the end of the recordset or clone.
And put this in the open even, probably very "Hackish" of me but it seems to be working, I even tested with all records deleted.


Code:
Private Sub Form_Open(Cancel As Integer)

If Me.Recordset.RecordCount = 1 Then
Me.Recordset.MoveNext
Me.Recordset.MoveFirst
End If

End Sub
Just a note to you about this. You should NOT use the Form Open event for recordset things because the records have not been loaded yet. Use the form's LOAD event for things like getting information about the form's recordset and clone, etc.
 
Dont know if this will help, but do you have the following anywhere to get correct count?

Me.RecordsetClone.movelast

just a note, this helped me with my subform.....I placed it in the On current of the sub form....

Me.RecordsetClone.MoveLast
Me.RecordsetClone.MoveFirst


I was having difficulty with the subform navigation buttons enabling

thanks
 

Users who are viewing this thread

Back
Top Bottom