Results 1 to 2 of 2
  1. #1
    wardw is offline Advanced Beginner
    Windows 7 64bit Access 2000
    Join Date
    May 2013
    Location
    Hines, Oregon
    Posts
    41

    Can't Enable a button when moving to different record

    In a form I have buttons to navigate to First Record, Next Record, Previous Record, and Last Record. When the First Record button (btnGotoFirstRecord) is clicked, the form goes to the first record, which has the First Record button disabled, because the first record is already showing (need to do the same for Previous Record, when I get this problem figured out).

    This works fine, but if I then go to any other records the First Record button is still disabled. I've tried to detect that another record is being displayed in the form, to re-Enable the button, but I can't figure out which Form event to use for that--or even whether this is the best way to re-Enable a button.

    This all seems like overkill, but my users will be very non-computer-savvy, and I'd like things to be as obvious as possible for them.

    Here's the code I'm using for the button:



    Code:
    Private Sub btnGotoFirstRecord_Click()
         Dim LResponse As Integer
         'If the current record has been changed, warn that changes won't be saved
         If Me.Dirty Then
            LResponse = msgbox("Changes will not be saved.", vbOKCancel + vbDefaultButton1 + vbExclamation, "Harney County Library: Obituary Records")
            If LResponse = vbCancel Then
               Exit Sub
            ElseIf LResponse = vbOK Then
            'Undo the changes
               Me.Undo
               'Set focus on some other control (can't disable a control that has focus)
               Me.btnGotoNextRecord.SetFocus
               'Disable the First Record button
               Me.btnGotoFirstRecord.Enabled = False
               'Go to first record
               DoCmd.RunCommand acCmdRecordsGoToFirst
               End If
         ElseIf Me.Dirty = False Then
            Me.btnGotoNextRecord.SetFocus
            Me.btnGotoFirstRecord.Enabled = False
            DoCmd.RunCommand acCmdRecordsGoToFirst
            End If
    End Sub

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Why do you have this in the btnGotoFirstRecord click event?

    Me.btnGotoFirstRecord.Enabled = False

    If you are going to goof around with enable = true and false for your controls, you will need to do a validation for each click event. What happens if you leave the control enabled and they are at the first record? Maybe you can validate by nesting an If Then statement. You can check to see if you are at the first or last record within the recordset and then

    If me.btnGotoFirstRecord.Enabled = False then
    me.btnGotoFirstRecord.Enabled = True
    End if

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

Similar Threads

  1. Replies: 2
    Last Post: 11-30-2012, 08:03 PM
  2. Enable/Disable Button
    By P.Malius in forum Programming
    Replies: 3
    Last Post: 09-07-2012, 08:36 AM
  3. Replies: 5
    Last Post: 03-13-2012, 12:28 PM
  4. Replies: 2
    Last Post: 01-11-2011, 02:00 PM
  5. Enable button in the master form when clicking in the detail
    By DistillingAccess in forum Programming
    Replies: 8
    Last Post: 08-03-2010, 10:54 AM

Tags for this Thread

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