Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox help, Please

Status
Not open for further replies.

wild007

Programmer
Sep 27, 2000
36
US
I am wondering if anyone out there has ever run into a situation where a listbox "remembers" the last value of the bound column from a previous record. Example:

I have a listbox which lists "notes" attached to a member's profile. If I double click on the entry it opens the appropriate note in an edit form, no problem. Now, If I re-open the form (without closing it, basically populating the form and listbox with different member's information), the other member has no notes, but when I double-click on the listbox, it opens the note from the previous member. I am doing this to error-trap the list box in case someone double clicks on it when it's empty. I am using access 2002 adp which connects to a sql server. I repopulate the listbox via VB/SQL. I can't figure out where it's getting that value from. Any help would greatly be appreciated. Thanks for taking time to read this. Post questions, If I'm unclear. It's late, I go home now...
 
I`ve no idea why this would happen as you say. The only thing I can think of that may cause this is that it could be within your method of opening up the notes form. It may reatin the value between calls if no other value is given. Can you post your Code for this part of there is any chnce of it being within there?

Ian
 
Thanks for the response. Here are the three main procedures that come into play, as far as I can see it. If I'm missing any pieces to the puzzle, I'd be happy to post.

Private Sub lstNotes_DblClick(Cancel As Integer)
If IsNull(Me.lstNotes) Or Me.lstNotes = "" Then
Exit Sub
End If
DoCmd.OpenForm "frmAddEditIndividualNote"
procFillEditIndividualNoteForm Forms!frmAddEditIndividualNote, Me.lstNotes
End Sub
==============================================================
Public Sub procFillEditIndividualNoteForm(vForm As Form, vNoteID As Integer)
OpenConn
Set rst = New ADODB.Recordset
strSQL = "SELECT tblNotes.*, IndInformalName, IndLastName " & _
"FROM tblNotes LEFT OUTER JOIN tblIndividuals ON tblNotes.IndividualID = tblIndividuals.IndividualID " & _
"Where tblNotes.NoteID = " & vNoteID
rst.CursorLocation = adUseClient
rst.Open strSQL, cnn, adOpenDynamic, adLockOptimistic
If rst.RecordCount = 0 Then
MsgBox "There are no notes for this individual to edit!"
DoCmd.Close acForm, "frmAddEditMailIndividualNote"
Exit Sub
Else
vForm.txtIndividualID = rst("IndividualID")
vForm.txtNoteID = rst("NoteID")
vForm.txtNoteDate = rst("NoteDate")
vForm.txtNoteSubject = rst("NoteSubject")
vForm.txtNoteBody = rst("NoteBody")
vForm.Caption = "Edit Note for " & rst("IndInformalName") & " " & rst("IndLastName")
vForm.txtNoteDate.SetFocus
End If
Set rst = Nothing
CloseConn

End Sub
================================================================
Private Sub cmdOk_Click()
OpenConn
Set rst = New ADODB.Recordset
If Left(Me.Caption, 4) = "Edit" Then
rst.Open "Select * from tblNotes Where NoteID = " & Me.txtNoteID, cnn, adOpenDynamic, adLockOptimistic
ElseIf Left(Me.Caption, 3) = "Add" Then
rst.Open "Select * from tblNotes", cnn, adOpenDynamic, adLockOptimistic
rst.AddNew
End If
rst("IndividualID") = Me.txtIndividualID
If IsNull(Me.txtNoteDate) Or Me.txtNoteDate = "" Then
MsgBox "You must enter in a date for this note!"
Me.txtNoteDate.SetFocus
Exit Sub
Else
rst("NoteDate") = Me.txtNoteDate
End If
If IsNull(Me.txtNoteSubject) Or Me.txtNoteSubject = "" Then
MsgBox "You must enter in a subject for this note!"
Me.txtNoteSubject.SetFocus
Exit Sub
Else
rst("NoteSubject") = Me.txtNoteSubject
End If
If IsNull(Me.txtNoteBody) Or Me.txtNoteBody = "" Then
MsgBox "You must enter information in the body for this note!"
Me.txtNoteBody.SetFocus
Exit Sub
Else
rst("NoteBody") = Me.txtNoteBody
End If
rst("EditBy") = vUser
rst("EditDate") = Now
rst.Update
Set rst = Nothing
CloseConn
Me.txtNoteID = ""
procFillIndividualNotesList Forms!frmIndividual, Me.txtIndividualID
DoCmd.Close
End Sub
 
I found out why it was doing this! It's a bug in VB6 with listbox controls. I'm not using CE, but this solution helped me out. I added the code:

If me.listboxname.listcount -1 <=0 then
Exit Sub
End If

It works!

I posted the article below:

FIX: An Empty ListBox Generates a DoubleClick Event

Q180833


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Windows CE Toolkit for Visual Basic 5.0, version 1.0

--------------------------------------------------------------------------------


SYMPTOMS
Double-clicking on an empty ListBox fires the DoubleClick event. The DoubleClick event is not supposed to fire when the ListBox is empty.



RESOLUTION
To work around the issue, add code to the DoubleClick event to detect an empty ListBox, and then exit the procedure as follows:




Private Sub List1_DblClick()
If List1.ListCount = 0 Then Exit Sub
MsgBox &quot;doubleclick&quot; 'this line won't execute when empty.
End Sub



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products that are listed at the beginning of this article.

This problem was corrected in Windows CE Toolkit for Visual Basic 6.0.


Additional query words: vbce5 vbce6vbce

Keywords : kbToolkit kbVBp kbVBp500bug kbVBp600fix kbOSWinCEsearch kbOSWinCE100 kbGrpDSVB
Issue type : kbbug
Technology : kbVBSearch kbAudDeveloper kbWinCETKVBSearch kbWinCESearch kbWinCETK100VB500
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top