I have a database I want to use for manually schedule students into class sections. Here is my schema:
The "enrollment" table tracks which members are enrolled in a particular class+section (section is really the primary item in which you enroll). I have a query which shows member currently enrolled in a section, and I a view that shows, for every student, which sections they are
not enrolled in. Both that query and view are displayed in table control widgets in a subform. Because the subform is linked to a parent (sub)form which includes the current sectionID value, I only see those students not enrolled in the section displayed. This is all very good
The problem I'm running into is how to select a set of rows from the "not enrolled" set and put them into the "enrolled" set. I have a macro which I've attached to a button which is part of the same form as the "not enrolled" view.
Code: Select all
Sub AddEnrollment (oEvent As Object) 'Button > Execute > event 'Used in form "Copy a part"
Dim oForm : oForm = oEvent.Source.Model.Parent
Dim oStatement : oStatement = oForm.ActiveConnection.createStatement()
Dim sSQL As String
REM I need to figure out which rows are selected
dim oGrid
oGrid=oForm.getbyname("TableControl")
Dim sColumns As String
sColumns = sColumns & """personID"""
sColumns = sColumns & ", ""sectionID"""
sSQL = "INSERT INTO ""enrollment"" ( ""personID"", ""sectionID"") " &_
"SELECT ""personID"", ""sectionID"" FROM ""UnenrolledView"" " &_
" WHERE ""sectionID"" = 0"
REM oStatement.executeUpdate( sSQL ) 'Execute the SQL command
sSQL = sSQL & " " & personID
MsgBox(sSQL)
End Sub
This, if I were to execute it instead of just displaying it, enrolls
everyone. What I can't figure out how to do is how to get the set of rows which are currently selected. If I put a break point in the macro and inspect the oGrid object, I can't figure out which fields I should be examining to get those selected rows. The value of the Selection member/element/whatever it's called OOO is null. If I look at the RowSet member, I see there is a BookMark field but it appears to be set the current record, where the little arrow pointer is. Since I have multiselect on, that's not good enough. I need to know the set of selected rows which may not even include that one. The rows contain the keys I need for the insert, I just can't figure out how to access them.
This is actually LibreOffice 4.0.2.2/Ubuntu 13.04.