C
carljonas
Dear honoured Expertise,
I´m struggling with the syntax below. My setup is a form with two
multi-select list boxes. A button click sends the details to a label
print out. I can get them to work separately but when I try to combine
them into a single query I run into troubles. The line "qdf.SQL =
strSQL" fails me. The script frame work is from the net and adapted
for my purpose. Perhaps someone can explain why the line "strCriteria
= Left(strCriteria, Len(strCriteria) - 3)" is needed? Any advice would
be most grateful.
Private Sub Kommandoknapp32_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strCriteria2 As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryUtskrift")
If Me!SelectCollector.ItemsSelected.Count > 0 Then
For Each varItem In Me!SelectCollector.ItemsSelected
strCriteria = strCriteria & "Utskrift_etikett_små_stor.Collector = " &
Chr(34) & Me!SelectSamling.ItemData(varItem) & Chr(34) & "OR "
Next varItem
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Else
strCriteria = "Utskrift_etikett_små_stor.Collector Like '*'"
End If
If Me!SelectSamling.ItemsSelected.Count > 0 Then
For Each varItem In Me!SelectSamling.ItemsSelected
strCriteria2 = strCriteria &
"Utskrift_etikett_små_stor.Donator = " & Chr(34) & Me!
SelectSamling.ItemData(varItem) & Chr(34) & "OR "
Next varItem
strCriteria2 = Left(strCriteria2, Len(strCriteria2) - 3)
Else
strCriteria2 = "Utskrift_etikett_små_stor_Donator Like '*'"
End If
strSQL = "Select * FROM Utskrift_etikett_små_stor " & "WHERE " &
strCriteria & " AND " & strCriteria2 & "; "
qdf.SQL = strSQL
DoCmd.OpenQuery "qryUtskrift"
Set db = Nothing
Set qdf = Nothing
End Sub
Thanks in advance // Jonas
I´m struggling with the syntax below. My setup is a form with two
multi-select list boxes. A button click sends the details to a label
print out. I can get them to work separately but when I try to combine
them into a single query I run into troubles. The line "qdf.SQL =
strSQL" fails me. The script frame work is from the net and adapted
for my purpose. Perhaps someone can explain why the line "strCriteria
= Left(strCriteria, Len(strCriteria) - 3)" is needed? Any advice would
be most grateful.
Private Sub Kommandoknapp32_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strCriteria2 As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryUtskrift")
If Me!SelectCollector.ItemsSelected.Count > 0 Then
For Each varItem In Me!SelectCollector.ItemsSelected
strCriteria = strCriteria & "Utskrift_etikett_små_stor.Collector = " &
Chr(34) & Me!SelectSamling.ItemData(varItem) & Chr(34) & "OR "
Next varItem
strCriteria = Left(strCriteria, Len(strCriteria) - 3)
Else
strCriteria = "Utskrift_etikett_små_stor.Collector Like '*'"
End If
If Me!SelectSamling.ItemsSelected.Count > 0 Then
For Each varItem In Me!SelectSamling.ItemsSelected
strCriteria2 = strCriteria &
"Utskrift_etikett_små_stor.Donator = " & Chr(34) & Me!
SelectSamling.ItemData(varItem) & Chr(34) & "OR "
Next varItem
strCriteria2 = Left(strCriteria2, Len(strCriteria2) - 3)
Else
strCriteria2 = "Utskrift_etikett_små_stor_Donator Like '*'"
End If
strSQL = "Select * FROM Utskrift_etikett_små_stor " & "WHERE " &
strCriteria & " AND " & strCriteria2 & "; "
qdf.SQL = strSQL
DoCmd.OpenQuery "qryUtskrift"
Set db = Nothing
Set qdf = Nothing
End Sub
Thanks in advance // Jonas