Databases Reference
In-Depth Information
Set oDataBase = Nothing
Set oWorkSpace = Nothing
End Sub
With the current database records now contained in the first list box, the next task to be tackled
is how to select the records that should be deleted. Notice in Figure 8.7 that four buttons are present
on the GUI. They are Add, Copy All, Remove, and Remove All. Each can be utilized to select
items to be removed from the current database. Items that are selected for removal can be populated
to the second list box by one of two means. They can be added from the list box that contains all
the database items, or they can be added directly from the database itself. An option button on the
GUI allows the user to choose which scheme to utilize. The advantage of reading items in directly
from the database is that order is always preserved in the listing of records. The advantage of
reading items in directly from the list box is speed, because the database only needs to be queried
once until such time it has been updated.
Keep in mind that these four buttons really constitute a “Shell Game,” where individual elements
of the database are selected and moved around at will. The concepts covered earlier in this chapter
in the “Using Pointers in Dynamic Database Algorithms” section are put to work in this example.
Taking the case first of copying over only the SELECTED elements in the left-hand list box:
Private Sub Button_Add_Click()
'Copy over only SELECTED 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?
If frm7Bind.ListBox_All.Selected(dbrow) = True Then
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
frm7Bind.ListBox_Chosen.List(lbrow, col) =
oRecordSet.Fields(col)
Next col
'Increment Listbox row
lbrow = lbrow + 1 'rows in listboxes begin @ 0!
End If
'Increment Database Row
dbrow = dbrow + 1 'rows in listboxes begin @ 0!
Search WWH ::




Custom Search