Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2009
    Posts
    6

    Unanswered: Hide a form button

    Is there a way I can hide a "Next Record" Macro button on a Form when I reach the last record?

    Same thing for hiding "Previous Record" when I am on the first record on a Form.

    Thanks, yes, rookie with Access.

    Dave

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You could try this (here with First, Last, Previous and Next command buttons):
    Code:
        If Me.Recordset.AbsolutePosition = 0 Then
            Me.Button_First.Enabled = False
            Me.Button_Previous.Enabled = False
            Me.Button_Last.Enabled = True
            Me.Button_Next.Enabled = True
        ElseIf Me.Recordset.AbsolutePosition = Me.Recordset.RecordCount - 1 Then
            Me.Button_First.Enabled = True
            Me.Button_Previous.Enabled = True
            Me.Button_Last.Enabled = False
            Me.Button_Next.Enabled = False
        Else
            Me.Button_First.Enabled = True
            Me.Button_Previous.Enabled = True
            Me.Button_Last.Enabled = True
            Me.Button_Next.Enabled = True
        End If
    Have a nice day!

  3. #3
    Join Date
    Dec 2009
    Posts
    6

    Hide a form button

    I built a command button (Command10) and in the coding it says

    Sub Command10_Click()

    End Sub

    When I put your code in between sub/end sub, I get error:

    Method or data member not found
    Then this line is highlighted:
    Me.Button_First.Enabled = False

    Thanks for all the help. I am a beginner but would like the command buttons disabled when I am on last record (for command button next I made) and disabled when I am on first record (for command button previous I made).

    Again, many thanks.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    In the lines Me.Button_XXXX.Enabled = you have to replace Button_XXXX by the name you gave to the command buttons on your form.
    Have a nice day!

  5. #5
    Join Date
    Dec 2009
    Posts
    6
    If the first line in my routine is Command10_click beside sub, then isn't the button name going to be Command10 or Command 10_click?

    Thanks again for your time....this will be awesome if it can be figured out.

    David

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. The code is to be placed in the Form_Current event code.
    2. If the name of the "Next Record" Macro button (as you name it) is "Command_Next", then the code should be like Me.Command_Next.Enabled = ... etc.

    So, let's suppose that you have two command buttons on your form, one that moves to the next record and is named Cmd_NextRecord and one that moves to the previous record and is named Cmd_PreviousRecord. The code you are looking for would be like this:
    Code:
    Private Sub Form_Current()
    
        If Me.Recordset.AbsolutePosition = 0 Then
            Me. Cmd_PreviousRecord.Enabled = False
            Me. Cmd_NextRecord .Enabled = True
        ElseIf Me.Recordset.AbsolutePosition = Me.Recordset.RecordCount - 1 Then
            Me. Cmd_PreviousRecord.Enabled = True
            Me. Cmd_NextRecord .Enabled = False
        Else
            Me. Cmd_PreviousRecord.Enabled = True
           Me. Cmd_NextRecord .Enabled = True
        End If
    
    End Sub
    Have a nice day!

  7. #7
    Join Date
    Dec 2009
    Posts
    6

    Hide buttons works!

    Thanks much....I thought it had to go to the button, but since I moved the original code to the form, it works beautifully.

    BIG BIG help, you're awesome.

    David

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •