list box problem!!!!!!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • THEAF
    New Member
    • Mar 2007
    • 52

    list box problem!!!!!!!!

    hi,
    i'm trying to create a reminder form on vb6 with access holding the reminders.
    i was given a code that checks the list box where all the reminders are shown on vb to see if any of the reminders match the actual time and date.
    my problem is that if there is a reminder that matches the actual time and date then the message box will show but the item shown in the message box is always the one on the top of the list.
    this is my form load and my listbox code:

    FORM LOAD
    [code=vb]
    Private Sub Form_Load()
    '
    Dim s() As String
    Dim ListTime As String
    Dim ListDate As String
    Dim name As String
    Dim i As Integer
    Set dbReminder = OpenDatabase(Ap p.Path & "\Password.mdb" )
    Set rsReminder = dbReminder.Open Recordset("Remi nder", dbOpenDynaset)

    If Not rsReminder.EOF Then rsReminder.Move First

    Do While Not rsReminder.EOF
    lstReminder.Add Item rsReminder!Rno & "." & " " & rsReminder!name & vbTab & vbTab & rsReminder!Date & vbTab & rsReminder!TIME
    lstReminder.Ite mData(lstRemind er.NewIndex) = rsReminder!Rno
    rsReminder.Move Next
    Loop

    Set dbReminder = OpenDatabase(Ap p.Path & "\Password.mdb" )
    Set rsReminder = dbReminder.Open Recordset("Remi nder", dbOpenDynaset)

    For i = 0 To lstReminder.Lis tCount - 1
    s = Split(lstRemind er.List(i), vbTab)
    'name = Mid(s(UBound(s) ))
    ListTime = Mid(s(UBound(s) ), 1, Len(s(UBound(s) )) - 3)
    ListDate = s(UBound(s) - 1)
    'MsgBox name = Mid(s(UBound(s) ), 1, Len(s(UBound(s) )))
    If ListTime = Mid(TIME, 1, Len(TIME) - 3) And ListDate = Date Then
    MsgBox rsReminder!Name
    End If

    Next
    End Sub

    LIST BOX
    Private Sub lstReminder_Cli ck()
    '
    rsReminder.Find First "Rno=" & (lstReminder.It emData(lstRemin der.ListIndex))

    rsReminder!Rno = frmReminder.txt no.Text
    rsReminder!name = frmReminder.txt Name.Text
    rsReminder!Date = frmReminder.txt Date.Text
    rsReminder!TIME = frmReminder.txt Time.Text
    rsReminder!Comm ents = frmReminder.txt Comment.Text
    End Sub
    [/code]
    in the for statement this is where the mesage is shown " MsgBox rsReminder!Name "
    please can you explain why it only shows the first item on the list.
    Last edited by debasisdas; Apr 21 '08, 12:58 PM. Reason: added code=vb tags
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    I believe that is because you are using the recordset on the MsgBox line instead of the lstbox data set.

    You are looping through your listbox, not your recordset so you need to use the when you use rsReminder!name you are only displaying the first record in the recordset, rather then which one you are on in the listbox.....

    You may need to do a sql select to get the "reminder name" from your recordset based on a key from your list box maybe. i guess unless you have the name in your list box.


    [code=vb]
    For i = 0 To lstReminder.Lis tCount - 1
    s = Split(lstRemind er.List(i), vbTab)
    'name = Mid(s(UBound(s) ))
    ListTime = Mid(s(UBound(s) ), 1, Len(s(UBound(s) )) - 3)
    ListDate = s(UBound(s) - 1)
    'MsgBox name = Mid(s(UBound(s) ), 1, Len(s(UBound(s) )))
    If ListTime = Mid(TIME, 1, Len(TIME) - 3) And ListDate = Date Then
    MsgBox rsReminder!Name 'this is from your recordset which will be set to the first record, you would need to find the correct record to display
    End If
    Next
    [/code]

    Comment

    Working...