Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2012
    Posts
    2

    Unanswered: Trying to replicate the go to record function

    Hello!

    I'm trying to replicate the go to record function in a text box + command button.
    Like the one in the navigation bar pictured below.
    So for example, you'd enter the ID of the record and hit the button.

    http://imgur.com/fa7zJ

    Any help would be great!
    Thanks

  2. #2
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    995
    Provided Answers: 2
    This is not difficult, but a little bit involved. You need to create the four command buttons on the form, set up the text boxes to allow you to amend the target record, and write a function that will move you to the desired record.

    Check out this excellent reference on recordsets: ADO Objects Recordset - DevGuru Quick Reference
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  3. #3
    Join Date
    Sep 2012
    Posts
    2
    Quote Originally Posted by weejas View Post
    write a function that will move you to the desired record.
    I've done the rest, this part here is where I'm getting stuck.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Here's a solution:
    Code:
    Private Function MoveTo(ByVal Position As String)
    
        Dim rst As DAO.Recordset
        
        Set rst = Me.RecordsetClone
        rst.Bookmark = Me.Bookmark 
        Select Case Position
            Case "First"
                rst.MoveFirst
            Case "Last"
                rst.MoveLast
            Case "Next"
                rst.MoveNext
                If rst.EOF = True Then rst.MoveLast
                '
                ' Optionally display a warning message:
                '
                ' Msgbox "This is the last record.",vbinformation,"MoveTo"
                '
            Case "Previous"
                rst.MovePrevious
                If rst.BOF = True Then rst.MoveFirst
                '
                ' Optionally display a warning message:
                '
                ' Msgbox "This is the first record.",vbinformation,"MoveTo"
                '
            Case Else
                MsgBox "Unknown position: " & Position, vbInformation, "MoveTo"
        End Select
        Me.Bookmark = rst.Bookmark
        rst.Close
        Set rst = Nothing
        
    End Function
    
    Private Sub Command_First_Click()
    
        MoveTo "First"
        
    End Sub
    
    Private Sub Command_Last_Click()
    
        MoveTo "Last"
        
    End Sub
    
    Private Sub Command_Next_Click()
    
        MoveTo "Next"
        
    End Sub
    
    Private Sub Command_Previous_Click()
    
        MoveTo "Previous"
        
    End Sub
    Have a nice day!

Posting Permissions

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