P
pietlinden
I am using the MultiPik from Developer's Handbook. Works a champ,
most of the time... but I managed to screw something up...
Here's the code from the book that I am using (in case you don't have
it)...
' MultiPik demo.
Private mmp As MultiPik
Private Sub Form_Open(Cancel As Integer)
' Four steps to using Multipik:
' 1. Instantiate the object
' 2. Set up the RowSourceType for the list boxes.
' If you did this at design time, you needn't
' do it now.
' 3. Register the 8 controls with the object
' 4. Tell it where your data comes from
' a collection for each - the Selected items and the Available
ones.
Dim colSel As Collection
Dim colAvail As Collection
Set mmp = New MultiPik
mmp.RegisterControls _
lstAvailable, lstSelected, _
cmdAddOne, cmdAddAll, _
cmdDeleteOne, cmdDeleteAll, _
cmdUp, cmdDown
' use a function to return the collection I want and assign it to
the variable...
'----- BEGIN MODIFICATIONS ----
Set colSel = RR_Queries(True)
Set colAvail = RR_Queries(False)
' ---- END MODIFICATIONS -----
mmp.SetCollections colAvail, colSel
Set colSel = Nothing
Set colAvail = Nothing
End Sub
Here's the function RR_Queries()
Public Function RR_Queries(ByVal blnIsSelected As Boolean) As
Collection
' RR=RecordReturning... so all Crosstabs and Selects...
Dim qdf As DAO.QueryDef
Dim intCounter As Integer
Dim colQs As Collection 'collection of query objects
Dim rs As DAO.Recordset
Set colQs = New Collection
For Each qdf In DBEngine(0)(0).QueryDefs
'query is in the table already...
'If the query is not already in the "always table", list it...
If Left$(qdf.Name, 1) = "~" Then
'do nothing
Else
If QueryIsSelected(qdf.Name) = blnIsSelected Then
If (qdf.Type = dbQSelect Or qdf.Type = dbQCrosstab)
And Left$(qdf.Name, 4) <> "zqry" Then
'Debug.Print qdf.Name
intCounter = intCounter + 1
colQs.Add Item:=qdf.Name, Key:=CStr(intCounter)
End If
End If
End If
Next qdf
'--Only add the sections to ONE of the lists... (Available)
If Not blnIsSelected Then
Set rs = DBEngine(0)(0).OpenRecordset("SELECT SectionName FROM
ztblSection ORDER BY Sequence;", dbOpenSnapshot)
Do Until rs.EOF
intCounter = intCounter + 1
colQs.Add Item:=rs.Fields("SectionName"), Key:=CStr
(intCounter)
rs.MoveNext
Loop
End If
Set RR_Queries = colQs
Set colQs = Nothing
End Function
When the code executes, it reaches this line:
If Not (colSel Is Nothing And colAvail Is Nothing) Then
mmp.SetCollections colAvail, colSel
End If
and I get "Error 3420: Object invalid or no longer set".
I guess i just don't get it... the types are right... (the function
returns a collection). What object is invalid? the reference to the
MultiPik is set... so what am I doing wrong?
Thanks for any help! I'm stymied. (and I would swear this was working
great the other day!)
most of the time... but I managed to screw something up...
Here's the code from the book that I am using (in case you don't have
it)...
' MultiPik demo.
Private mmp As MultiPik
Private Sub Form_Open(Cancel As Integer)
' Four steps to using Multipik:
' 1. Instantiate the object
' 2. Set up the RowSourceType for the list boxes.
' If you did this at design time, you needn't
' do it now.
' 3. Register the 8 controls with the object
' 4. Tell it where your data comes from
' a collection for each - the Selected items and the Available
ones.
Dim colSel As Collection
Dim colAvail As Collection
Set mmp = New MultiPik
mmp.RegisterControls _
lstAvailable, lstSelected, _
cmdAddOne, cmdAddAll, _
cmdDeleteOne, cmdDeleteAll, _
cmdUp, cmdDown
' use a function to return the collection I want and assign it to
the variable...
'----- BEGIN MODIFICATIONS ----
Set colSel = RR_Queries(True)
Set colAvail = RR_Queries(False)
' ---- END MODIFICATIONS -----
mmp.SetCollections colAvail, colSel
Set colSel = Nothing
Set colAvail = Nothing
End Sub
Here's the function RR_Queries()
Public Function RR_Queries(ByVal blnIsSelected As Boolean) As
Collection
' RR=RecordReturning... so all Crosstabs and Selects...
Dim qdf As DAO.QueryDef
Dim intCounter As Integer
Dim colQs As Collection 'collection of query objects
Dim rs As DAO.Recordset
Set colQs = New Collection
For Each qdf In DBEngine(0)(0).QueryDefs
'query is in the table already...
'If the query is not already in the "always table", list it...
If Left$(qdf.Name, 1) = "~" Then
'do nothing
Else
If QueryIsSelected(qdf.Name) = blnIsSelected Then
If (qdf.Type = dbQSelect Or qdf.Type = dbQCrosstab)
And Left$(qdf.Name, 4) <> "zqry" Then
'Debug.Print qdf.Name
intCounter = intCounter + 1
colQs.Add Item:=qdf.Name, Key:=CStr(intCounter)
End If
End If
End If
Next qdf
'--Only add the sections to ONE of the lists... (Available)
If Not blnIsSelected Then
Set rs = DBEngine(0)(0).OpenRecordset("SELECT SectionName FROM
ztblSection ORDER BY Sequence;", dbOpenSnapshot)
Do Until rs.EOF
intCounter = intCounter + 1
colQs.Add Item:=rs.Fields("SectionName"), Key:=CStr
(intCounter)
rs.MoveNext
Loop
End If
Set RR_Queries = colQs
Set colQs = Nothing
End Function
When the code executes, it reaches this line:
If Not (colSel Is Nothing And colAvail Is Nothing) Then
mmp.SetCollections colAvail, colSel
End If
and I get "Error 3420: Object invalid or no longer set".
I guess i just don't get it... the types are right... (the function
returns a collection). What object is invalid? the reference to the
MultiPik is set... so what am I doing wrong?
Thanks for any help! I'm stymied. (and I would swear this was working
great the other day!)