Hi guys -
I work at a school and have a form that lists the classnames in a listbox. I have code that allows the selection of multiple items before it opens the form with pupils from the selected classes.
This code worked when my database was mdb(2000) but now it is accdb (2007) it comes up with the error above.
Pointers please?
Many thanks
Private Sub Command47_Click()
On Error GoTo Err_Command47_Click
Dim stDocName As String
stDocName = "Pupil Profile"
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryMultiSelect")
For Each varItem In Me!List44.ItemsSelected
strCriteria = strCriteria & "," & Chr(34) & Me!List44.ItemData(varItem) & Chr(34)
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT * FROM Pupils " & _
"WHERE Pupils.Form IN(" & strCriteria & ");"
qdf.SQL = strSQL
Rem DoCmd.OpenQuery "qryMultiSelect"
DoCmd.OpenForm stDocName
Set db = Nothing
Set qdf = Nothing
Exit_Command47_Click:
Exit Sub
Err_Command47_Click:
MsgBox Err.Description
Resume Exit_Command47_Click
End Sub
I work at a school and have a form that lists the classnames in a listbox. I have code that allows the selection of multiple items before it opens the form with pupils from the selected classes.
This code worked when my database was mdb(2000) but now it is accdb (2007) it comes up with the error above.
Pointers please?
Many thanks
Private Sub Command47_Click()
On Error GoTo Err_Command47_Click
Dim stDocName As String
stDocName = "Pupil Profile"
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryMultiSelect")
For Each varItem In Me!List44.ItemsSelected
strCriteria = strCriteria & "," & Chr(34) & Me!List44.ItemData(varItem) & Chr(34)
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT * FROM Pupils " & _
"WHERE Pupils.Form IN(" & strCriteria & ");"
qdf.SQL = strSQL
Rem DoCmd.OpenQuery "qryMultiSelect"
DoCmd.OpenForm stDocName
Set db = Nothing
Set qdf = Nothing
Exit_Command47_Click:
Exit Sub
Err_Command47_Click:
MsgBox Err.Description
Resume Exit_Command47_Click
End Sub