-1

I'm, trying to navigate through my records but when I press the buttons, nothing happens. I'm using Jet 4.0 and an Access DB.

I'm not sure what I'm doing wrong but if anyone can help me in the right direction, it would be appreciated.

Code:

Private Sub showData(ByVal CurrentRow)

    CurrentRow = 0

    Dad.Fill(dst, "patrolDB")

    TextBox27.Text = dst.Tables("patrolDB").Rows(CurrentRow)("ID").ToString.ToUpper
    DateTimePicker1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroldate").ToString.ToUpper
    TextBox2.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroltime").ToString.ToUpper
    ComboBox1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroltype").ToString.ToUpper
    ComboBox2.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolsite").ToString.ToUpper
    ComboBox4.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolloc").ToString.ToUpper
    ComboBox3.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolofficer").ToString.ToUpper
    RichTextBox1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolnotes").ToString.ToUpper




Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

    If CurrentRow <> dst.Tables("patrolDB").Rows.Count - 1 Then

        CurrentRow += 1
        showData(CurrentRow)

    End If
    MsgBox("You've reached the last record.")

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    index = 0
    showData(CurrentRow)
End Sub

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    If CurrentRow <> 0 Then


        CurrentRow -= 1
        showData(CurrentRow)

    End If

    MsgBox("You've reached the first record.")

End Sub

Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click

    CurrentRow = dst.Tables("patrolDB").Rows.Count - 1
    showData(CurrentRow)
End Sub
YowE3K
  • 23,852
  • 7
  • 26
  • 40
Ian Probets
  • 123
  • 1
  • 9
  • 3
    In ShowData you always set the CurrentRow to zero. This will display always the first row. Remove it (and look at how to fill the DataSet just once, not at each call to ShowData) – Steve Jun 25 '17 at 17:40
  • After you finally read [ask] and take the [tour] you could also look into databinding to let NET do a lot of that for you and get rid of a lot of code – Ňɏssa Pøngjǣrdenlarp Jun 25 '17 at 18:39

1 Answers1

0
Dim table As DataTable

Private Sub LoadData()
    CurrentRow = 0
    Dad.Fill(dst, "patrolDB")
    table = dst.Tables("patrolDB") 'for the comfort
    ShowCurrentRow()
End Sub

Private Sub ShowCurrentRow()
    TextBox27.Text = table.Rows(CurrentRow)("ID").ToString.ToUpper
    DateTimePicker1.Text = table.Rows(CurrentRow)("patroldate").ToString.ToUpper
    TextBox2.Text = table.Rows(CurrentRow)("patroltime").ToString.ToUpper
    ComboBox1.Text = table.Rows(CurrentRow)("patroltype").ToString.ToUpper
    ComboBox2.Text = table.Rows(CurrentRow)("patrolsite").ToString.ToUpper
    ComboBox4.Text = table.Rows(CurrentRow)("patrolloc").ToString.ToUpper
    ComboBox3.Text = table.Rows(CurrentRow)("patrolofficer").ToString.ToUpper
    RichTextBox1.Text = table.Rows(CurrentRow)("patrolnotes").ToString.ToUpper
End Sub

'go to next
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
    If CurrentRow <> table.Rows.Count - 1 Then
        CurrentRow += 1
        ShowCurrentRow()
    Else MsgBox("You've reached the last record.")
    End If
End Sub

'go to prev
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
    If CurrentRow <> 0 Then
        CurrentRow -= 1
        ShowCurrentRow()
    Else MsgBox("You've reached the first record.")
    End If
End Sub

'go to start
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    index = 0
    ShowCurrentRow()
End Sub

'go to last
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
    CurrentRow = table.Rows.Count - 1
    ShowCurrentRow()
End Sub
dovid
  • 6,354
  • 3
  • 33
  • 73