Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding a 'next record' button when at the end of the records 1

Status
Not open for further replies.

leaners

Technical User
May 16, 2006
12
AU
I have a button which takes you to the next record.
I want it to disappear when the user looks at the last record.

But I also want the last record to not be a blank record, so that the user is forced to use my other button which adds a new record.

I also have a button which takes you to the previous record and i want to to disappear when the user looks at the first record.

My form name is Customer, my next record button is named Command31 and my previous record button is named Command32.

Seems simple enough but impossible for a beginner. Please help.

 
It is best to give controls names that mean something, so in this idea, I have called the command button for the next record, cmdNext, and for the previous record, cmdPrevious.
Code:
Private Sub Form_Current()
    Dim lngCurrRec As Long
    Dim lngRecCount As Long
    
    'Get the last record.
    Me.RecordsetClone.MoveLast

    'Get the current record.
    Me.RecordsetClone.Bookmark = Me.Bookmark

    'Store the information
    lngCurrRec = Me.RecordsetClone.AbsolutePosition + 1
    lngRecCount = Me.RecordsetClone.RecordCount
    
    'Hide or show the buttons according to the position.
    Me.cmdPrev.Visible = (lngCurrRec > 1)
    Me.cmdNext.Visible = (lngCurrRec < lngRecCount)

End Sub

You will need to set Allow Additions to No (False), to prevent people adding records, and only set it to Yes (True) when someone clicks the proper button. You may also with to set Cycle to Current Record.
 
Thanks, it works for one of the forms, but when i try use it on another of my forms there is an error. If i wanted to use the code in 2 of my forms what should i do?
 
Sorry to bother you it works fine now
 
No problem. It is not complete code, just a snippet. For example, there is no error checking and:
[tt]'Get the last record.
Me.RecordsetClone.MoveLast[/tt]
Will cause an error if there are no records.
 
How are ya leaners . . .

Here's my version of controlling the buttons. In the [blue]On Current[/blue] event of the form, copy/paste the following:
Code:
[blue]   If Me.CurrentRecord = Me.Recordset.RecordCount Then
      Me![purple][b]NextButtonName[/b][/purple].Enabled = False
   Else
      Me![purple][b]NextButtonName[/b][/purple].Enabled = True
   End If

   If Me.CurrentRecord = 1 Then
      Me![purple][b]PrevButtonName[/b][/purple].Enabled = False
   Else
      Me![purple][b]PrevButtonName[/b][/purple].Enabled = True
   End If[/blue]
I'll try to sneak in the [blue]Add Button[/blue] at work later today . . .

Calvin.gif
See Ya! . . . . . .
 
The add button would be a nice addition
 
leaners . . .

To remove the new record line set the forms [blue]Allow Additions[/blue] property to [blue]Yes[/blue] . . .

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top