my .recordcount is always -1 what will i do... im using an mysql database.. here's my code pls help me
VB Code:
  1. Option Explicit
  2. Dim AY As String
  3. Dim ls As ListItem
  4.  
  5.  
  6. Private Sub cmdAdd_Click()
  7. frmAcademicYear.addstate = True
  8. frmAcademicYear.Show
  9.  
  10. End Sub
  11.  
  12. Private Sub cmdClose_Click()
  13. Unload Me
  14. End Sub
  15.  
  16. Private Sub cmdDelete_Click()
  17. On Error GoTo Err:
  18. With tbAcademicYear
  19.     '---------------------------------
  20.     'Check if there is no record
  21.     '---------------------------------
  22. '    If .RecordCount < 1 Then MsgBox "No school year in the list.Please check it!", vbExclamation, "CSRS version 1": Exit Sub
  23.     '---------------------------------
  24.     'Confirm deletion of record
  25.     '---------------------------------
  26.     Dim ans As Integer
  27.     Dim pos As Integer
  28.     ans = MsgBox("Are you sure you want to delete the selected record?", vbCritical + vbYesNo, "Confirm Record Delete")
  29.     If ans = vbYes Then
  30.         '-----------------------------
  31.         'Delete the record
  32.         '-----------------------------
  33.         pos = Val(LV1.SelectedItem)
  34.        '  tbAcademicYear.Open "Select * from tbacademicyear where AcademicYearTitle='" & LV1.SelectedItem.Text & "'", cn, adOpenDynamic, adLockOptimistic
  35.              If .EOF = False Then
  36.                 .Delete adAffectCurrent
  37.                 '.Requery
  38.              End If
  39.        
  40.         If .RecordCount > 0 Then
  41.             .AbsolutePosition = pos
  42.             If .EOF Then .MoveFirst
  43.             '---------------------------------
  44.             'Fill listview
  45.             '---------------------------------
  46.             pos = .AbsolutePosition
  47.             load_rec
  48.             LV1.ListItems.Item(pos).EnsureVisible
  49.             LV1.ListItems.Item(pos).Selected = True
  50.             .AbsolutePosition = LV1.SelectedItem
  51.             '---------------------------------
  52.             'End-fill listview
  53.             '---------------------------------
  54.         'Else
  55.            ' LV1.ListItems.Clear
  56.         End If
  57.                 MsgBox "Record has been successfully deleted.", vbInformation, "Confirm"
  58.     End If
  59.     ans = 0
  60.     pos = 0
  61.     Me.MousePointer = vbDefault
  62. End With
  63. Exit Sub
  64. Err:
  65.     MsgBox Err.Description, vbCritical, "Academic Year"
  66.  
  67. End Sub
  68.  
  69. Private Sub cmdEdit_Click()
  70.  
  71. With tbAcademicYear
  72. 'If .RecordCount < 1 Then MsgBox "No school year in the list.Please check it!", vbExclamation, "Titus School of Multimedia": Exit Sub
  73.  
  74. If Not LV1.SelectedItem = "" And Not tbAcademicYear.RecordCount < 1 Then .AbsolutePosition = LV1.SelectedItem
  75. frmAcademicYear.addstate = False
  76. frmAcademicYear.Show
  77. Me.Enabled = False
  78. 'End If
  79. End With
  80. End Sub
  81.  
  82. Private Sub Form_Load()
  83. tbAcademicYear.Open "Select * from tbacademicyear", cn, adOpenDynamic, adLockOptimistic
  84. CallFields
  85. End Sub
  86.  
  87. Private Sub CallFields()
  88. With tbAcademicYear
  89.     LV1.ListItems.Clear
  90.     While .EOF = False
  91.         Set ls = LV1.ListItems.Add(, , .Fields(0))
  92.         .MoveNext
  93.     Wend
  94. End With
  95. End Sub
  96.  
  97. Sub load_rec()
  98. Screen.MousePointer = vbHourglass
  99.  
  100. CallFields
  101. Screen.MousePointer = vbDefault
  102. End Sub
  103.  
  104. Private Sub Form_Unload(Cancel As Integer)
  105. tbAcademicYear.Close
  106. End Sub