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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing DBList 4

Status
Not open for further replies.

CptnMike

Programmer
Feb 5, 2003
13
US
I can populate the DBList box, but how do you clear it for use with another list?
 
You might have to double check, but for most list boxes and combo boxes it like this,

Code:
List1.Clear

zemp
 
Thanks for the reply Zemp, but the "list1.clear" does not work on a DBlist or a DBCombo box. They are just too easy to use, but almost worthless if you cant clear them out.
 
DBList and DBCombo are bound controls (populated by a recordset). If you want control over the contents try using ListBox, ComboBox, MSFlexgrid or a Listview control

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'
 
Ok John, Thanks. I started with the listbox and thought there must be a better way. Guess not. I'm kinda new at this database thing so, back to the books!
 
Take a look at some of the free on line tutorials I have posted in thread222-628778.

zemp
 
If it's bound to a recordset, can you have a dummy recordset with no records and set that to be the data source??

Regards,

Patrick
 
Thanks again Zemp! That will give me some more reading besides the 9 books I already have on it! I've found that sometimes the tutorials on the web are better explained than in the tech books.

That's a thought Patrick....I may try working something like that. When I use a simple bind on the ADODC and list box, nothing shows up. Like on a DBList, using no code, it populates the list. But, I can't seem to be able to re-populate it with another field list. Tried using ADODC1 and ADODC2 and ADODC3 on the same form, but it crashes when I add the third. Two seems to work ok.

Now I'm back to using a different Form for each listbox and populating it with code. I'm trying to make this program as simple to use as I can because the people using it still think a mouse has fur on it.....

Thanks again guys!
 
Just a thought that may not fit what you are doing but.....

I often use the List View control to display results from a Select statement.

Fill the List view by looping through the recordset.
If you are just displaying records, it works great

I then have the user either dblclick the selected item or use a command button to load another form to display the details of that individual item should they want to edit that record.

Seems to be pretty efficient, but most of the time I am using it where each potential record has many fields. I only select a "summary" of the records and list them, then make a selection. So far the users seem to like this.

I use a connection string and open a connection instead of an ADODC control.

Simple version of the code:

Private Sub LoadList()
On Error GoTo fail
'fill the listview
Dim Item As ListItem, v As Variant, f As Field

sethead ' sub that sets the column headers
Do While Not adoPrimaryRS.EOF
For Each f In adoPrimaryRS.Fields
'get the field value
v = pffield(f)
If f.Name = "Something" Then
Set Item = LVRS.ListItems.Add(, , v)
Else
'rest are sub items
'somethingmay not have an associated IDNUM when dropped so
'check for that and set it to a default
If f.Name = "IDNUM" Then
If IsNull(v) Or v = "" Then v = "Empty Drop"
End If
Item.ListSubItems.Add , , v & ""
End If
Next
If LVRS.ListItems.Count > 100 Then
Dim l As Long
If l = LVRS.ListItems.Count Mod 100 = 0 Then DoEvents
End If
adoPrimaryRS.MoveNext
Loop
LVRS.Visible = True
colwidth 'set width of columns dynamically
Exit Sub
fail:
MsgBox Err.Description, vbExclamation
End Sub

don't foget this

Public Function pffield(ByVal f As Field) As Variant
'return value in recordset field ,converting any nulls to empty string
If IsNull(f.Value) Then
pffield = ""
Else
pffield = f.Value
End If
End Function

The next routine is a sub to clear the listview in the event you have too many records. I once filled a list view control with over 52,000 records (don't even ask!!!!) so I developed this to keep me out of trouble

Public Sub GetRidOfIt(ByVal f As Form)
'clear list view control
'if the listview contains too many records the app may lock on clear.
'If not locked, the process may take some time so indicate something is happening
'Experimentation on various old pc's lead me to the 300 record cut off, but newer
'pcs are so fast that a couple of thousand records could be cleared without
'a problem I would suspect
On Error GoTo fail
If f.LVRS.ListItems.Count > 300 Then
Dim Item As ListItem
Dim l As Long 'just a counter for display puposes
l = f.LVRS.ListItems.Count
For Each Item In f.LVRS.ListItems
Set Item = Nothing 'destroy the item
f.Status.SimpleText = "Record " & l & "has been removed."
l = l - 1 'count it down.
Next
Else
f.LVRS.ListItems.Clear
End If
Exit Sub
fail:
MsgBox Err.Description, vbExclamation
End Sub

There is a lot more to each form, but this should explain the basics.

if not let me know

Terry (cyberbiker)
 
Hey Terry! Thanks! No, that won't work for what I am trying, but just glancing thru it, it will work perfectly for another project!! Copied it off and I'll go thru it tomorrow.......

Thanks again!
 
Glad to be of help

Just be certain you order your select statement the same as the column headers (or do it dynamically from the names of the record set fields)


Terry (cyberbiker)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top