0

I have records in my dsatabase in access, the table is called "Add Form". I have created a form in vb which i would like to Delete a selected record by the record from the table to show in the respective textboxes and then the user would click delete to delete the record and either click Next\Previous to navigate to another record. my code for the Next button:

If inc <> MaxRows - 1 Then
    inc = MaxRows - 1
    NavigateRecords()
ElseIf inc = -1 Then
    MsgBox("This is the first record")
End If

the navigate function is here :

Private Sub NavigateRecords()
    Student_IDTextBox.Text = ds.Tables("Add Form").Rows(inc).Item(0)
    Student_NameTextBox.Text = ds.Tables("Add Form").Rows(inc).Item(1)
    Date_of_BirthDateTimePicker.Text = ds.Tables("Add Form").Rows(inc).Item(2)
    AddressTextBox.Text = ds.Tables("Add Form").Rows(inc).Item(3)
    E_mailTextBox.Text = ds.Tables("Add Form").Rows(inc).Item(4)
    AllergiesTextBox.Text = ds.Tables("Add Form").Rows(inc).Item(5)
    Emergency_Contact_NumberTextBox.Text = ds.Tables("Add Form").Rows(inc).Item(6)
End Sub

But its giving me this error:

Object reference not set to an instance of an object.

for the first line of the code under the navigate sub.

Please could you help me to program the button to go to the next record in the database.

Jota
  • 16,103
  • 7
  • 54
  • 89
Philip Dyson
  • 11
  • 1
  • 7
  • 1) Where are you initializing the `ds` variable -- `Set ds = Something`? 2) Also note that binding forms and controls to data is something that Access does extremely well, and is not something you generally need to do by yourself. 3) Your code can be much more concise if you say `Dim row As Row: Set row = ds.Tables("Add Form").Rows(inc): Student_IDTextBox.Text = row(0): ` etc. 4) Since this is VBA, you don't need to explicitly set the `Text` property -- `Student_IDTextBox = row(0)`. – Zev Spitz Oct 06 '13 at 19:54
  • Almost all cases of `NullReferenceException` are the same. Please see "[What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net)" for some hints. – John Saunders Oct 13 '13 at 02:51

0 Answers0