Results 1 to 4 of 4
  1. #1
    aquaraider is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    14

    Question Why ".RecordCount - 1" tells me its the last when I open a form?

    Hello,

    I'm trying to make navigation buttons by myself (For a better UI design). Normally if I do accept new records in a form, I can still go to next record (which is a new record) by click next button while the form showing the last record.

    But I still want to add new records, and stop next record button from go to a new record by disable it.

    Here is my code,

    Private Sub Form_Current()

    Dim rs As Object
    Set rs = Me.Recordset

    'If is the last
    If rs.AbsolutePosition = rs.RecordCount - 1 Then
    'Disable New
    Me.Next.Enabled = False
    'Enable Previous
    Me.Previous.Enabled = True

    ElseIf rs.AbsolutePosition = 0 Then
    Me.Previous.Enabled = False
    Me.Next.Enabled = True

    Else
    Me.Next.Enabled = True
    Me.Previous.Enabled = True

    End If

    End Sub

    ' Next & Previous are navigation buttons I made by button wizard
    It works well, except when I open this form. Problem is when I open the form (which shows 1st record by default), next button is already disabled, and previous button is still enable.



    But after select another record by a combobox I made, both button works well, they do disable and enable at the right time.

    Which I guess there's some problem in Recordset, but I don't know how to work it out.

    I've tried to use EOF and BOF, it's not working, says something like recordset type not match (sorry but I'm not using English MS Access so I don't know what this error msg will be in English)

    Would anyone give me some hints?

    Thank you.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,923
    In the OnLoad event of the form do a Me.Recordset.MoveLast and then a Me.Recordset.MoveFirst and the problem should go away. It will slow down the loading a bit though.

  3. #3
    aquaraider is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2009
    Posts
    14
    Thank you RG, you saved me again!

    BTW, I've tested those values when I tried to solve it by myself before I asked here, I've created a button.

    Private Sub Command96_Click()
    Dim test As Object
    Set test = Me.Recordset
    MsgBox test.AbsolutePosition & test.RecordCount
    End Sub
    What strange is, although next/previous buttons are not working when I open the form, I do click this cmd96 button, it tells me 0139 (I have 138 record and now it is the 1st), which means AbsolutePosition=0 and RecordCount=139, it is correct, so I think my code for disable/enable is correct.

    So I can't understand why it won't work without MoveLast and MoveFirst, I'm quite interest with this.

    Thanks again.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,923
    .RecordCount is not guaranteed accurate until after you have done a .MoveLast.

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

Similar Threads

  1. Replies: 21
    Last Post: 06-03-2009, 05:54 PM
  2. aSTR = Dir("C:\*.*") >> "Type Mismatch"
    By JGrant in forum Programming
    Replies: 1
    Last Post: 03-28-2009, 05:17 AM
  3. Export to .rtf of "104-" converts to "-655&qu
    By Sherri726 in forum Import/Export Data
    Replies: 0
    Last Post: 12-19-2006, 03:16 PM
  4. Replies: 2
    Last Post: 08-31-2006, 12:19 PM
  5. "Count" and "Countif" in Reports
    By JMantei in forum Reports
    Replies: 1
    Last Post: 06-20-2006, 02:20 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