Databases Reference
In-Depth Information
database fails to load into the list box due to an error (special or null characters, etc.). Each time
such a behavior occurs, the index of the database element will be one greater than the current list
box element.
The case of copying all the items over from the first list box is even easier because no checking
needs to be done.
Private Sub Button_CopyAll_Click()
'Copy over ALL Items to Chosen Listbox FROM Database
Dim index As Integer, DeletedItems As Integer
Dim lbrow As Integer, dbrow As Integer, col As Integer
On Error Resume Next
Select Case OB_db.Value
'Load From Database
Case True
Call DBConnect
oRecordSet.MoveFirst
ListBox_Chosen.ColumnCount = oRecordSet.Fields.Count
Do Until oRecordSet.EOF '*** Use For Loop to .Fields of All
listbox instead?
ListBox_Chosen.AddItem 'Add next row to list
'Track Items that have moved, 0 = not selected, else set
to position + 1
ReDim Preserve dBptr(dbrow)
dBptr(dbrow) = lbrow + 1
For col = 0 To oRecordSet.Fields.Count
'ListBox_All.AddItem oRecordSet.Fields(strDBField)
'Debug.Print oRecordSet.Fields(2)
frm7Bind.ListBox_Chosen.List(lbrow, col) =
oRecordSet.Fields(col)
Next col
'Increment Listbox row
lbrow = lbrow + 1 'rows in listboxes begin @ 0!
'Increment Database Row
dbrow = dbrow + 1 'rows in listboxes begin @ 0!
oRecordSet.MoveNext ' Move to next record in table.
Loop
Call CleanUpQuery
'Load from Listbox
Case False
'Copy over ALL Items to Chosen Listbox
'Set Number of Columns
frm7Bind.ListBox_Chosen.ColumnCount =
frm7Bind.ListBox_All.ColumnCount
For index = 0 To frm7Bind.ListBox_All.ListCount - 1
ListBox_Chosen.AddItem 'Add next row to list
Search WWH ::




Custom Search