Results 1 to 3 of 3
  1. #1
    emilyrogers is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    46

    Buttons on form to navigate through records

    I have this code


    Code:
    Private Sub Form_Current()
     Dim rst As DAO.Recordset
     Dim lngCount As Long
     Set rst = Me.RecordsetClone
     With rst
     lngCount = RecordsetClone
     If lngCount > 0 Then
     .MoveFirst
     .MoveLast
     lngCount = .RecordCount
     End If
     End With
     Me.Text241 = "Record " & Me.CurrentRecord & " of " & lngCount
    
    End Sub
    And The idea is that "Text241" is a textbox at the bottom of the form with 2 buttons either side of it eg Go to first, go to prev, go to next , go to last.
    and what i want displayed in the textbox is " Record X of Y" X being the record number and Y being the total number of records.
    what am I doing wrong?

    Thank You In Advance!

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    try:

    Code:
    Private Sub Form_Current()
     Dim rst As DAO.Recordset
     Dim lngCount As Long
     Set rst = Me.RecordsetClone
     With rst
    .movelast
    .movefirst
     lngCount = rst.recordcount
     End With
     Me.Text241 = "Record " & Me.CurrentRecord & " of " & lngCount
    
    End Sub
    you might also be better off setting a private variable for the entire form's module, setting it with recordcount on form OPEN and then referring to that on the "current" event. that way code doesn't have to open a data set on everyrecord.

  3. #3
    emilyrogers is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    46
    Thank You so much! I have sorted it!

    Quote Originally Posted by ajetrumpet View Post
    try:

    Code:
    Private Sub Form_Current()
     Dim rst As DAO.Recordset
     Dim lngCount As Long
     Set rst = Me.RecordsetClone
     With rst
    .movelast
    .movefirst
     lngCount = rst.recordcount
     End With
     Me.Text241 = "Record " & Me.CurrentRecord & " of " & lngCount
    
    End Sub
    you might also be better off setting a private variable for the entire form's module, setting it with recordcount on form OPEN and then referring to that on the "current" event. that way code doesn't have to open a data set on everyrecord.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form and Buttons
    By rmohebian in forum Forms
    Replies: 1
    Last Post: 02-14-2011, 09:57 AM
  2. Replies: 6
    Last Post: 11-05-2010, 10:11 AM
  3. VBA to Navigate form
    By asmith in forum Access
    Replies: 3
    Last Post: 09-30-2010, 11:37 AM
  4. Navigate window to import txt
    By Macallan60 in forum Access
    Replies: 11
    Last Post: 05-13-2010, 12:30 PM
  5. Replies: 2
    Last Post: 03-25-2010, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums