By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,961 Members | 1,332 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,961 IT Pros & Developers. It's quick & easy.

list box problem!!!!!!!!

P: 52
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
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. '
  3. Dim s() As String
  4. Dim ListTime As String
  5. Dim ListDate As String
  6. Dim name As String
  7. Dim i As Integer
  8.     Set dbReminder = OpenDatabase(App.Path & "\Password.mdb")
  9.     Set rsReminder = dbReminder.OpenRecordset("Reminder", dbOpenDynaset)
  10.  
  11. If Not rsReminder.EOF Then rsReminder.MoveFirst
  12.  
  13. Do While Not rsReminder.EOF
  14.     lstReminder.AddItem rsReminder!Rno & "." & " " & rsReminder!name & vbTab & vbTab & rsReminder!Date & vbTab & rsReminder!TIME
  15.     lstReminder.ItemData(lstReminder.NewIndex) = rsReminder!Rno
  16.     rsReminder.MoveNext
  17. Loop
  18.  
  19.     Set dbReminder = OpenDatabase(App.Path & "\Password.mdb")
  20.     Set rsReminder = dbReminder.OpenRecordset("Reminder", dbOpenDynaset)
  21.  
  22. For i = 0 To lstReminder.ListCount - 1
  23. s = Split(lstReminder.List(i), vbTab)
  24. 'name = Mid(s(UBound(s)))
  25. ListTime = Mid(s(UBound(s)), 1, Len(s(UBound(s))) - 3)
  26. ListDate = s(UBound(s) - 1)
  27. 'MsgBox name = Mid(s(UBound(s)), 1, Len(s(UBound(s))))
  28. If ListTime = Mid(TIME, 1, Len(TIME) - 3) And ListDate = Date Then
  29.    MsgBox rsReminder!Name
  30. End If
  31.  
  32. Next
  33. End Sub
  34.  
  35. LIST BOX
  36. Private Sub lstReminder_Click()
  37. '
  38. rsReminder.FindFirst "Rno=" & (lstReminder.ItemData(lstReminder.ListIndex))
  39.  
  40. rsReminder!Rno = frmReminder.txtno.Text
  41. rsReminder!name = frmReminder.txtName.Text
  42. rsReminder!Date = frmReminder.txtDate.Text
  43. rsReminder!TIME = frmReminder.txtTime.Text
  44. rsReminder!Comments = frmReminder.txtComment.Text
  45. End Sub
  46.  
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.
Apr 21 '08 #1
Share this Question
Share on Google+
1 Reply


jeffstl
Expert 100+
P: 432
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.


Expand|Select|Wrap|Line Numbers
  1. For i = 0 To lstReminder.ListCount - 1
  2.      s = Split(lstReminder.List(i), vbTab)
  3.      'name = Mid(s(UBound(s)))
  4.      ListTime = Mid(s(UBound(s)), 1, Len(s(UBound(s))) - 3)
  5.      ListDate = s(UBound(s) - 1)
  6.      'MsgBox name = Mid(s(UBound(s)), 1, Len(s(UBound(s))))
  7.      If ListTime = Mid(TIME, 1, Len(TIME) - 3) And ListDate = Date Then
  8.              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
  9.      End If
  10. Next
  11.  
Apr 23 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.