Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Database Form Navigation using command buttons for moveNext etc

Posted on 2003-12-05
3
Medium Priority
?
450 Views
Last Modified: 2008-03-06
Hello,
I am using Access 2002 and VBA

I have added buttons to a form to navigate through the records using the four common options moveNext MovePrevious, MoveLast, MoveFirst and AddNewRecord.
linking the onClick event procedure like this:
 
Private Sub cmdMoveNext_Click()
 DoCmd.GoToRecord , , acNext
End Sub

This works fine to allow me to work through the records, but I need to make the coding more robust to prevent errors appearing when:
 trying to move to the record before the first record
 trying to move to the record after the add new record

The coding needs to incorporate options to disable the buttons
 i.e. disable the buttons using cmdMovePrevious.enabled = false when sitting on the first record

The coding must work using ADO.
I will be grateful for any tips and advice
0
Comment
Question by:sy2180
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:bagger99
ID: 9881732
Mayber an easier solution than ADO :
You can disable the command button after a user has clicked it :

Private Sub cmdMoveFirst_Click()
    DoCmd.GoToRecord , , acFirst
    Me!EmployeeID.SetFocus 'set focus to a field on the form, otherwise you can't disable the button
    Me.cmdMoveFirst.Enabled = False
End Sub

Also set the default enabled value of this button on 'false', and back to 'true' whenever a user clicks on one of the other buttons :
Private Sub cmdMoveNext_Click()
 DoCmd.GoToRecord , , acNext
 Me.cmdMoveFirst.Enabled = True
End Sub

Apply the same logic to the cmdMoveLast button.

HTH
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9881744
Is there any reason you aren't using the standard form navigation methods (Form property Navigation Buttons = Yes)

If you want to check if you are at the start/end of the recordset, assuming you are using a bound form (ADO  or DAO),

Me.Recordset.AbsolutePostion = 0 when at the start of the recordset
Me.Recordset.AbsolutePostion = Me.Recordset.RecordCount-1 when at the end of the recordset


Private Sub Form_Current()
  If Me.Recordset.AbsolutePostion = 0 Then
     cmdMovePrevious.Enabled = False
  Else
     cmdMovePrevious.Enabled = True
  End If
 
  If Me.Recordset.AbsolutePostion = Me.Recordset.RecordCount - 1 Then
     cmdMoveNext.Enabled = False
  Else
     cmdMoveNext.Enabled = True
  End If
End Sub
0
 
LVL 2

Accepted Solution

by:
bagger99 earned 420 total points
ID: 9881855
Since the AbsolutePosition property is new to me, I tried it out, but get the error message "Object doesn't support this property".

Private Sub Form_Current()

    If Me.Recordset.AbsolutePostion = 0 Then
        MsgBox "0"
    End If
   
End Sub

The Recordsetclone object does't support it either.

You'll have to slightly adapt the code :

Private Sub Form_Current()
   
    Dim rst As dao.Recordset
    Set rst = Me.RecordsetClone
   
    If rst.AbsolutePosition = 0 Then
         cmdMovePrevious.Enabled = False
    End If
   'etcetera
End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question