title: Unable to add records more than 28 in access database
body: <p>I am making my first project using vb.net and access. I am trying to develop a project in which the data of patients of the is added from different counters.it works fine till 22nd or 23rd record entered. after that adding new record over writes the last saved record. </p>
  
  <p>to check the database i deleted some record (say after deletion there are 13 records left in the database) and tried to add new record, it gives the same problem, the 13th record is overwritten by the new record.</p>
  
  <p>i deleted all the records and tried to add new record, the first record successfully entered but after that new record entry over writes the last (only) record.    </p>
  
  <p>i'm unable to understand the problem</p>
  
  <p>code for saving data is </p>
  
  <pre><code> Private Sub Save()
  
          'Dim st As String
  
          Dim str As String
          btnSave_Click = False
          str = check
          If Not str = "" Then
              MsgBox(str, vbInformation, "Patient Registration")
              btnSave_Click = False
              Exit Sub
          End If
  
          If conn.State = 0 Then
              Module1.openConnection()
          End If
  
          If Not rsDept Is Nothing Then
              If rsDept.State = 0 Then
                  Call openRecordset("SELECT * FROM tblDept", rsDept)
              End If
          Else
              Call openRecordset("SELECT * FROM tblDept", rsDept)
          End If
  
          If Not rsData Is Nothing Then
              If rsData.State = 0 Then
                  Call openRecordset("Select * from tblPatientRecord", rsData)
              End If
          Else
              Call openRecordset("Select * from tblPatientRecord", rsData)
          End If
  
          conn.BeginTrans()
          On Error GoTo ProcError
          If Not (rsData.BOF And rsData.EOF) Then
  
              rsData.MoveLast()
              Call addData(rsData)
          Else
              Call addData(rsData)
          End If
          conn.CommitTrans()
          MsgBox("Patient's Record Saved Successfully...!", MsgBoxStyle.Information, "Patient Registration")
  
          Call loadDataListview()
          Call fieldDisable()
          Call Disable_SearchButtons()
          btnSave_Click = True
          comDepart.Enabled = False
          conn.Close()
  
  ProcError:
          If Err.Number &lt;&gt; 0 Then
              conn.RollbackTrans()
              MsgBox(Err.Number &amp; "   " &amp; Err.Description)
              Call addNewR()
              Exit Sub
          End If
  
      End Sub
  
  
      Private Sub addData(rData As ADODB.Recordset)
          Dim rsPaymentType As New ADODB.Recordset
          'Dim str As String
  
          If Not (rData.BOF And rsData.EOF) Then
              rData.MoveFirst()
              If rData.RecordCount &gt; 0 Then
                  Do
                      If txthn.Text = rData("hNumber").Value Then
                          Call addVisit()
                          conn.Execute("update tblPatientRecord set visitNo = '" &amp; vNo.Text &amp; "' where hNumber = '" &amp; txthn.Text &amp; "'")
  
                          Call fieldEnable()
                         Exit Sub
                      End If
                      rData.MoveNext()
                  Loop Until rData.EOF
              End If
          End If
  
          rData.AddNew()
          rData("hNumber").Value = txthn.Text
          rData("fName").Value = txtfn.Text
          rData("contactNo").Value = txtContact.Text
          rData("address").Value = txtaddress.Text
          rData("cnic").Value = txtcnic.Text
          'rData("cnic").Value = rCNIC()
          rsData("visitNo").Value = vNo.Text
          rsData("cnicSD").Value = comSD.Text
  
          ''Add gender as selected
  
          If radmale.Checked = True Then
              rData("gender").Value = radmale.Text
          ElseIf radfemale.Checked = True Then
              rData("gender").Value = radfemale.Text
          Else
              rData("gender").Value = " - "
          End If
  
          If txtAge.Text &lt; 105 Or Year(dtAgePicker.Value) &lt; 1915 Then
              Call addAge()
              'MsgBox("data of tblAge added")
          Else
              MsgBox("Please Enter Correct Age ", vbCritical, "")
              txtAge.Select()
              Exit Sub
          End If
  
          If comRelation.Text = "Select Relation with Patient" Or comRelation.Text = "" Then
              comRelation.Text = "Not Selected"
          End If
          If txtfh.Text = "" Then
              txtfh.Text = "Not Given"
          End If
  
          Call addRelation()
  
          'Save Department ID as selected
          If comDepart.Text &lt;&gt; "Select Department" Then
              Call addVisit()
              'MsgBox("data of tblVisit added")
          Else
              MsgBox("Please Enter the Department ", vbCritical, "")
              comDepart.Select()
              Exit Sub
          End If
  
          If Not rsPaymentType Is Nothing Then
              If rsPaymentType.State = 0 Then
                  Call openRecordset("Select * from tblPaymentType", rsPaymentType)
                  'MsgBox("Patient record is open" &amp; rsData.State)
              End If
          Else
              Call openRecordset("Select * from tblPaymentType", rsPaymentType)
              'MsgBox("Patient record is open")
          End If
  
          If Not (rsPaymentType.BOF And rsPaymentType.EOF) Then
              rsPaymentType.MoveFirst()
              Do
                  If rsPaymentType("paymentType").Value = comPaymentType.Text Then
                      rData("paymentType").Value = rsPaymentType("paymentTypeID").Value
                      Exit Do
                  Else
                      rData("paymentType").Value = 0
                  End If
                  rsPaymentType.MoveNext()
              Loop Until rsPaymentType.EOF
  
          End If
  
          rsData.Update()
      End Sub
  
  Public Function h_N0_Generator(rs As ADODB.Recordset) As String
  
          Dim str, p1() As String
          Dim auto_long As Long
          Dim hMonth As String
          Dim strCounter As String, temp As String
  
          'this counter file is added to make the hNumber unique for multiple counter /* in the file counter number is added and have respective counter number only*/ 
          FileOpen(FileNum, "C048ounter.txt", OpenMode.Input)
          strCounter = LineInput(FileNum)
          FileClose(FileNum)
          If strCounter = "" Then
              strCounter = "1"
          End If
  
          hMonth = Month(Now).ToString("D2")
  
  
          If (rs.EOF And rs.BOF) Then
              h_N0_Generator = "NIRM-" &amp; Year(Now) &amp; "-" &amp; hMonth &amp; "-" &amp; "00000" &amp; strCounter
          Else
  
              rs.MoveLast()
              str = rs("HNumber").Value
  
              p1 = str.Split("-")
              ' check if the current month is the same as in last stored Hospital No or not 
              'if yes the last five digits increment otherwise it restarts with 0
              If p1(2) = Month(Now) And p1(1) = Year(Now) Then
                  temp = Right(rs(0).Value, 6)
                  auto_long = Left(temp, 5) + 1
                  h_N0_Generator = "NIRM-" &amp; Year(Now) &amp; "-" &amp; hMonth &amp; "-" &amp; Right("00000" &amp; auto_long, 5) &amp; strCounter
              Else
                  h_N0_Generator = "NIRM-" &amp; Year(Now) &amp; "-" &amp; hMonth &amp; "-" &amp; "00000" &amp; strCounter
              End If
          End If
          'Return auto_num
  
      End Function
  </code></pre>