Navigation Buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created my own set of navigation buttons for last previous next first
and new records. How can I also create the box which tells you which record
you are currently looking at, and the one which tells you how many records
there are in total?

Also, an error message comes up when i click previous if on the first record
and when I click next when on the last. How do I blank out the previous
button when on first record, and how do I change the function of the next
button to "new record" when on the last record?

I am trying to do this as I want to move the navigation buttons from the
bottom of the screen so if anyone knows a way of doing this without creating
all new buttons then that would be even better.
 
One way is to place two text boxes on the form: txtCurrent and txtTotal.
Then, in the form's Current event:

Me.txtCurrent = Me.CurrentRecord
Me.RecordsetClone.MoveLast
Me.txtTotal = Me.RecordsetClone.RecordCount

You could also add an unbound text box txtCounter, with its Control source
set to something like:
[txtCurrent] & " of " & [txtTotal]
You could hide the txtCurrent and txtTotal

I expect (although I haven't tried it) that you could also do this with
strings in VBA rather than with hidden text boxes:

Dim strCurrent, strTotal as String

strCurrent = Me.CurrentRecord
Me.RecordsetClone.MoveLast
strTotal = Me.RecordsetClone.RecordCount

Me.txtCounter = strCurrent & " of " & strTotal

To enable/diable navigation buttons (cmdPrevious and cmdNext), also in the
form's Current event (watch for wrapping in the newsreader window):

' Enable navigation buttons only when there are records available
cmdPrevious.Enabled = Not Me.CurrentRecord = 1
cmdNext.Enabled = (Me.CurrentRecord = 1 And Me.Recordset.RecordCount >
1) _
Or Me.CurrentRecord < Me.Recordset.RecordCount
 
I did it slightly different because filtered queries were not giving me

the proper counts all of the time
and also in this particular app they were NOT allowed to create NEW
records in this query.


==============================
at the top of the module I have...............................


Option Compare Database


Public saveCountAM As Integer
=============================
On form load.......................................


Private Sub Form_Load()


saveCountAM = DCount("[AM]", "Query - Summary for AM") '
'count number of records in this particular filtered
query


End Sub


============================
in the onCurrent event I have .........................................



Private Sub Form_Current()

Me.lblPosition.Caption = "Record " & Me.Form.CurrentRecord & " of "
& saveCountAM

If Me.Form.CurrentRecord = 1 Then
Me.backbutton.Visible = False
Else
Me.backbutton.Visible = True
End If


If Me.Form.CurrentRecord = saveCountAM Then
Me.forwardbutton.Visible = False
Else
Me.forwardbutton.Visible = True
End If


End Sub


============================================
I did not worry about the first and last record button since they will
not cause a problem if they are pressed and you are already there.


It may not be the classiest, but it is simple.


Ron
 
Back
Top