Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2003
    Posts
    160

    Unanswered: Command buttons on a form

    Hi! I have a form in which I created command buttons for record navigations.

    I have three command buttons. prev, next, add

    I want to disable the next command button when the form is in newrecord position.

    Here is the code I wrote

    Private Sub Form_Current()
    If Me.NewRecord = True Then
    cmdprev.SetFocus
    cmdnext.Enabled = False
    Else
    cmdnext.Enabled = True
    End If

    End Sub

    I am getting error, saying error 424: object required

    Any help!
    Thanks
    Vad

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    on what line are you getting the error?

  3. #3
    Join Date
    Sep 2003
    Location
    Gloucester
    Posts
    28
    I have a set of fairly intelligent buttons here

    Copy and paste this into On Current event procedure for the form.


    Private Sub Form_Current()
    Dim RecClone As Recordset
    Set RecClone = Me.RecordsetClone()
    If Me.NewRecord Then
    GoFirst.Enabled = True
    GoPrevious.Enabled = True
    GoNext.Enabled = False
    GoLast.Enabled = True
    AddNew.Enabled = True
    Exit Sub
    End If
    AddNew.Enabled = Me.AllowAdditions

    If RecClone.RecordCount = 0 Then
    GoFirst.Enabled = False
    GoNext.Enabled = False
    GoPrevious.Enabled = False
    GoLast.Enabled = False

    Else
    GoFirst.Enabled = True
    GoLast.Enabled = True

    RecClone.Bookmark = Me.Bookmark

    RecClone.MovePrevious
    GoPrevious.Enabled = Not (RecClone.BOF)
    RecClone.MoveNext

    RecClone.MoveNext
    GoNext.Enabled = Not (RecClone.EOF)
    RecClone.MovePrevious
    End If

    RecClone.Close
    End Sub


    Add to the onClick for the Next Record

    Private Sub GoNext_Click()
    On Error GoTo Err_GoNext_Click

    DoCmd.GoToRecord , , acNext
    Exit_GoNext_Click:
    Exit Sub

    Err_GoNext_Click:
    MsgBox Err.Description
    Resume Exit_GoNext_Click

    End Sub

    Same again for Previous button click

    Private Sub GoPrevious_Click()
    On Error GoTo Err_GoPrevious_Click
    DoCmd.GoToRecord , , acPrevious
    Exit_GoPrevious_Click:
    Exit Sub
    Err_GoPrevious_Click:
    MsgBox Err.Description
    Resume Exit_GoPrevious_Click

    End Sub

    And again for First Record Click


    Private Sub GoFirst_Click()
    On Error GoTo Err_GoFirst_Click
    DoCmd.GoToRecord , , acFirst
    Exit_GoFirst_Click:
    Exit Sub

    Err_GoFirst_Click:
    MsgBox Err.Description
    Resume Exit_GoFirst_Click

    End Sub

    And for the Last Record

    Private Sub GoLast_Click()
    On Error GoTo Err_GoLast_Click
    DoCmd.GoToRecord , , acLast
    Exit_GoLast_Click:
    Exit Sub
    Err_GoLast_Click:
    MsgBox Err.Description
    Resume Exit_GoLast_Click

    End Sub

    And for adding a New Record


    Private Sub AddNew_Click()
    On Error GoTo Err_AddNew_Click
    DoCmd.GoToRecord , , acNewRec
    Exit_AddNew_Click:
    Exit Sub
    Err_AddNew_Click:
    MsgBox Err.Description
    Resume Exit_AddNew_Click

    End Sub

  4. #4
    Join Date
    Aug 2003
    Posts
    160

    Command buttons

    Hi! Thank U very much I will try with this one.

    Bye
    Vad

Posting Permissions

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