pls help me why is it my .absoluteposition is alwas = -3
Printable View
pls help me why is it my .absoluteposition is alwas = -3
Please give a little more description and the code you tried. :)
I don't do databases that frequently, so I had to google to find that it is a ADO problem. :D
Edit:
Please don't post duplicate threads. Thanks. :)
http://www.vbforums.com/showthread.p...wpost&t=452014
give us more details. post your codes.
here's my code
VB Code:
Option Explicit Dim AY As String Dim ls As ListItem Private Sub cmdAdd_Click() frmAcademicAE.addstate = True frmAcademicAE.Show End Sub Private Sub cmdClose_Click() Unload Me End Sub Private Sub cmdDelete_Click() On Error GoTo Err: With tbAcademicYear '--------------------------------- 'Check if there is no record '--------------------------------- ' If .RecordCount < 1 Then MsgBox "No school year in the list.Please check it!", vbExclamation, "CSRS version 1": Exit Sub '--------------------------------- 'Confirm deletion of record '--------------------------------- Dim ans As Integer Dim pos As Integer ans = MsgBox("Are you sure you want to delete the selected record?", vbCritical + vbYesNo, "Confirm Record Delete") If ans = vbYes Then '----------------------------- 'Delete the record '----------------------------- pos = Val(LV1.SelectedItem) ' tbacademicyear.Open "Select * from tbacademicyear where academicyearTitle='" & LV1.SelectedItem.Text & "'", cn, adOpenDynamic, adLockOptimistic If .EOF = False Then .Delete adAffectCurrent '.Requery End If If .RecordCount > 0 Then .AbsolutePosition = pos If .EOF Then .MoveFirst '--------------------------------- 'Fill listview '--------------------------------- pos = .AbsolutePosition load_rec LV1.ListItems.Item(pos).EnsureVisible LV1.ListItems.Item(pos).Selected = True .AbsolutePosition = LV1.SelectedItem '--------------------------------- 'End-fill listview '--------------------------------- 'Else ' LV1.ListItems.Clear End If MsgBox "Record has been successfully deleted.", vbInformation, "Confirm" End If ans = 0 pos = 0 Me.MousePointer = vbDefault End With Exit Sub Err: MsgBox Err.Description, vbCritical, "Academic Year" End Sub Private Sub cmdEdit_Click() With tbAcademicYear 'If .RecordCount < 1 Then MsgBox "No school year in the list.Please check it!", vbExclamation, "Titus School of Multimedia": Exit Sub If Not LV1.SelectedItem = "" And Not tbAcademicYear.RecordCount < 1 Then .AbsolutePosition = LV1.SelectedItem frmAcademicAE.addstate = False frmAcademicAE.Show Me.Enabled = False 'End If End With End Sub Private Sub Form_Load() tbAcademicYear.CursorLocation = adUseClient tbAcademicYear.Open "Select * from tbacademicyear", cn, adOpenKeyset, adLockOptimistic CallFields End Sub Private Sub CallFields() With tbAcademicYear LV1.ListItems.Clear While .EOF = False Set ls = LV1.ListItems.Add(, , .Fields(0)) .MoveNext Wend End With End Sub Sub load_rec() Screen.MousePointer = vbHourglass CallFields Screen.MousePointer = vbDefault End Sub Private Sub Form_Unload(Cancel As Integer) tbAcademicYear.Close End Sub Private Sub LV1_Click() Dim a As String a = tbAcademicYear.AbsolutePosition If Not tbAcademicYear.RecordCount < 1 Then a = LV1.SelectedItem End Sub
Duplicate threads merged.
Please do not post the same question in multiple threads.
Hack - you must have missed another thread - we talked about this more yesterday...
http://www.vbforums.com/showthread.p...count+movelast
@mheiy - why are you still checking for .RecordCount > 0???
You need to "jiggle" the recordset as TechGnome and I suggested yesterday.
That means after immediately after you read the recordset from the database you do a MOVELAST so that the entire recordset is on the client side. Then the recordcount will not be -1 anymore.
Fix this first before trying to understand why the rest of your logic is flawed.