Help... listbox question

gen23
04-14-2004, 09:16 AM
How can I delete an item from a listbox without having to delete the item before it. For example: Within a listbox are apple and orange, how can I delete orange without deleting apple?

Private Sub add_Click()
ado1.Recordset.AddNew
ado1.Recordset.Fields("names") = Trim(Text2.Text)
ado1.Recordset.Update
display
Text2 = Clear
Text2.SetFocus
End Sub

Private Sub cmddelete_Click()
List1.RemoveItem Selected
End Sub

Private Sub Form_Load()
Text1.Text = Format(Date, "mmddyy")
Label1.Caption = Time
List1.Appearance = ado1.Recordset.Fields(0)
End Sub

Private Sub display()
List1.AddItem ado1.Recordset.Fields(0)

End Sub

This is what I've done so far... but I have another problem... I cannot display the content of my database in a listbox.. how can I do that?

Thanks...

candela
04-14-2004, 09:34 AM
your problem is deleting a line? or showing data?

shiba126
04-15-2004, 04:21 AM
What you can do is redefine all access to your database. Add an ADO control to your form, then in the code (Form_Load()) write::

Private Sub Form_Load()
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Set db = New ADODB.Connection
Set rs = New ADODB.RecordSet
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=LOCATIONTODATABASEandFILENAME.mdb;Persist Security Info=False
db.Open
sSql = "Select * From table"
rs.Open sSql, db, 1, 3
Do While Not rs.EOF
ListBox.AddItem rs("field")
rs.MoveNext
Loop
End Sub


Thats how to fill the list box with all entries

deleting entries::


List1.RemoveItem (List1.ListIndex)


This Removes the Item that is selected at that present moment


Hope this helps,

Chris

gen23
04-15-2004, 10:49 AM
Thanks Chris... I'll do it :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum