Navigation buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vaniKanabathy
    New Member
    • Mar 2008
    • 52

    Navigation buttons

    Hi, i want to do navigation button like first, previous, next and last using command button. When user click the first button, the first record in access must appear . I do using the coding below but it not going to first record , it goes to records in 288 row.

    Private Sub cmdFirst_Click( )

    ' Open a connection.
    Set conn = New ADODB.Connectio n
    conn.Connection String = "Provider=Micro soft.Jet.OLEDB. 4.0; " & _
    "Data Source=" & App.Path & "\Everspark2.md b"
    conn.CursorLoca tion = adUseClient
    'Open the Connection
    conn.Open


    'Define an SQL statement (asking for all columns of the Solicitor table)
    sqlString = " SELECT * FROM Alternator"

    'execute the SQL statement and put the resulting set of record in recordset variable
    Set rs1 = conn.Execute(sq lString)

    rs1.MoveFirst
    GetFields

    rs1.Close
    conn.Close

    End Sub

    Private Sub GetFields()
    ' Places field data into the text boxes -

    txtAltId1.Text = rs1.Fields(0).V alue
    txtEversparkNo1 .Text = rs1.Fields(1).V alue
    End Sub

    Plz help me.Thanks in advance.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    What is the problem with your code ?

    1.use the move methods
    2.check for BOF/EOF
    3.display the field in desired control.

    Comment

    • anuragshrivastava64
      New Member
      • Jan 2007
      • 66

      #3
      try using Order by in Select statemenyt

      Comment

      • vaniKanabathy
        New Member
        • Mar 2008
        • 52

        #4
        Thanks for the reply . I had put the orderby clause in the coding , its work fine to first and last button but it not moved to next or previous data when click the associate button.

        Comment

        • debasisdas
          Recognized Expert Expert
          • Dec 2006
          • 8119

          #5
          try to use this sample code
          [code=vb]
          Private Sub cmdFirst_Click( )
          On Error GoTo GoFirstError

          adoPrimaryRS.Mo veFirst
          Exit Sub

          GoFirstError:
          MsgBox Err.Description
          End Sub

          Private Sub cmdLast_Click()
          On Error GoTo GoLastError

          adoPrimaryRS.Mo veLast
          Exit Sub

          GoLastError:
          MsgBox Err.Description
          End Sub

          Private Sub cmdNext_Click()
          On Error GoTo GoNextError

          If Not adoPrimaryRS.EO F Then adoPrimaryRS.Mo veNext
          If adoPrimaryRS.EO F And adoPrimaryRS.Re cordCount > 0 Then
          Beep

          adoPrimaryRS.Mo veLast
          End If

          mbDataChanged = False

          Exit Sub
          GoNextError:
          MsgBox Err.Description
          End Sub

          Private Sub cmdPrevious_Cli ck()
          On Error GoTo GoPrevError

          If Not adoPrimaryRS.BO F Then adoPrimaryRS.Mo vePrevious
          If adoPrimaryRS.BO F And adoPrimaryRS.Re cordCount > 0 Then
          Beep

          adoPrimaryRS.Mo veFirst
          End If

          Exit Sub

          GoPrevError:
          MsgBox Err.Description
          End Sub
          [/code]

          Comment

          • vaniKanabathy
            New Member
            • Mar 2008
            • 52

            #6
            What is mbDataChanged = False at line 31 ?
            I had try the coding the error message of
            Operators is not allowed when the object is closed . What does the error mean ?

            Comment

            • debasisdas
              Recognized Expert Expert
              • Dec 2006
              • 8119

              #7
              this code is part of an application. Just comment / remove that line.

              Comment

              • vaniKanabathy
                New Member
                • Mar 2008
                • 52

                #8
                On Error GoTo GoPrevError

                If Not rs1.BOF Then rs1.MovePreviou s
                If rs1.BOF And rs1.RecordCount > 0 Then
                Beep

                rs1.MoveFirst
                End If

                Exit Sub

                GoPrevError:
                MsgBox Err.Description

                I had used this code. But error occured. The error is
                "Operation is not allowed when the object is closed "
                What does the error mean ?

                Comment

                • debasisdas
                  Recognized Expert Expert
                  • Dec 2006
                  • 8119

                  #9
                  it seems you lack basic knowledge of Vb programming.

                  Have you opened the recordset or is the recordset open while you are tring to use the move methods.

                  Comment

                  Working...