kann ich folgenden Code erweitern, sodass ich von 3 Listenfeldern auswählen kann?
Den unteren Code habe ich selbst versucht, aber es funktioniert leider nicht...
Private Sub Befehl0_Click()
Dim strSQL As String
Dim strC1 As String, strC2 As String
Dim Anz&, I&, tmp As Variant
strSQL = "SELECT TOP 10 [Sales Zahlen].Fondsname, Sum([Sales Zahlen].AuM_) AS SummevonAuM_, Sum([Sales Zahlen].NetflowsMTD) AS SummevonNetflowsMTD, Sum([Sales Zahlen].NetflowsYTD) AS SummevonNetflowsYTD FROM [Sales Zahlen]"
With Me.Liste0
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC1 = strC1 & "Country='" & .ItemData(tmp) & "' or "
Next tmp
strC1 = Left$(strC1, Len(strC1) - 4)
End If
End With
With Me.Liste2
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC2 = strC2 & "Konzern='" & .ItemData(tmp) & "' or "
Next tmp
strC2 = Left$(strC2, Len(strC2) - 4)
End If
End With
If strC1 <> "" And strC2 <> "" Then
strSQL = strSQL & " where (" & strC1 & ") and (" & strC2 & ")"
ElseIf strC1 <> "" Then
strSQL = strSQL & " where " & strC1
ElseIf strC2 <> "" Then
strSQL = strSQL & " where " & strC2
End If
strSQL = strSQL & " GROUP BY [Sales Zahlen].Fondsname ORDER BY Sum([Sales Zahlen].AuM_) DESC;"
'MsgBox strSQL
CurrentDb.QueryDefs("Abfrage1").SQL = strSQL
DoCmd.OpenQuery "Abfrage1", acViewNormal
End Sub
Versuch:
Private Sub Befehl0_Click()
Dim strSQL As String
Dim strC1 As String, strC2 As String, strC3 As String
Dim Anz&, I&, tmp As Variant
strSQL = "SELECT TOP 10 [Sales Zahlen].Fondsname, Sum([Sales Zahlen].AuM_) AS SummevonAuM_, Sum([Sales Zahlen].NetflowsMTD) AS SummevonNetflowsMTD, Sum([Sales Zahlen].NetflowsYTD) AS SummevonNetflowsYTD FROM [Sales Zahlen]"
With Me.Liste0
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC1 = strC1 & "Country='" & .ItemData(tmp) & "' or "
Next tmp
strC1 = Left$(strC1, Len(strC1) - 4)
End If
End With
With Me.Liste2
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC2 = strC2 & "Konzern='" & .ItemData(tmp) & "' or "
Next tmp
strC2 = Left$(strC2, Len(strC2) - 4)
End If
End With
With Me.Liste9
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC3 = strC3 & "Partner1='" & .ItemData(tmp) & "' or "
Next tmp
strC3 = Left$(strC3, Len(strC3) - 4)
End If
End With
If strC1 <> "" And strC2 <> "" And strC3 <> "" Then
strSQL = strSQL & " where (" & strC1 & ") and (" & strC2 & ") and (" & strC2 & ")"
ElseIf strC1 <> "" Then
strSQL = strSQL & " where " & strC1
ElseIf strC2 <> "" Then
strSQL = strSQL & " where " & strC2
ElseIf strC3 <> "" Then
strSQL = strSQL & " where " & strC3
End If
strSQL = strSQL & " GROUP BY [Sales Zahlen].Fondsname ORDER BY Sum([Sales Zahlen].AuM_) DESC;"
'MsgBox strSQL
CurrentDb.QueryDefs("Abfrage1").SQL = strSQL
DoCmd.OpenReport "Bericht1", acViewPreview
End Sub
Den unteren Code habe ich selbst versucht, aber es funktioniert leider nicht...
Private Sub Befehl0_Click()
Dim strSQL As String
Dim strC1 As String, strC2 As String
Dim Anz&, I&, tmp As Variant
strSQL = "SELECT TOP 10 [Sales Zahlen].Fondsname, Sum([Sales Zahlen].AuM_) AS SummevonAuM_, Sum([Sales Zahlen].NetflowsMTD) AS SummevonNetflowsMTD, Sum([Sales Zahlen].NetflowsYTD) AS SummevonNetflowsYTD FROM [Sales Zahlen]"
With Me.Liste0
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC1 = strC1 & "Country='" & .ItemData(tmp) & "' or "
Next tmp
strC1 = Left$(strC1, Len(strC1) - 4)
End If
End With
With Me.Liste2
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC2 = strC2 & "Konzern='" & .ItemData(tmp) & "' or "
Next tmp
strC2 = Left$(strC2, Len(strC2) - 4)
End If
End With
If strC1 <> "" And strC2 <> "" Then
strSQL = strSQL & " where (" & strC1 & ") and (" & strC2 & ")"
ElseIf strC1 <> "" Then
strSQL = strSQL & " where " & strC1
ElseIf strC2 <> "" Then
strSQL = strSQL & " where " & strC2
End If
strSQL = strSQL & " GROUP BY [Sales Zahlen].Fondsname ORDER BY Sum([Sales Zahlen].AuM_) DESC;"
'MsgBox strSQL
CurrentDb.QueryDefs("Abfrage1").SQL = strSQL
DoCmd.OpenQuery "Abfrage1", acViewNormal
End Sub
Versuch:
Private Sub Befehl0_Click()
Dim strSQL As String
Dim strC1 As String, strC2 As String, strC3 As String
Dim Anz&, I&, tmp As Variant
strSQL = "SELECT TOP 10 [Sales Zahlen].Fondsname, Sum([Sales Zahlen].AuM_) AS SummevonAuM_, Sum([Sales Zahlen].NetflowsMTD) AS SummevonNetflowsMTD, Sum([Sales Zahlen].NetflowsYTD) AS SummevonNetflowsYTD FROM [Sales Zahlen]"
With Me.Liste0
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC1 = strC1 & "Country='" & .ItemData(tmp) & "' or "
Next tmp
strC1 = Left$(strC1, Len(strC1) - 4)
End If
End With
With Me.Liste2
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC2 = strC2 & "Konzern='" & .ItemData(tmp) & "' or "
Next tmp
strC2 = Left$(strC2, Len(strC2) - 4)
End If
End With
With Me.Liste9
Anz = .ItemsSelected.Count
If Anz <> 0 And Anz < .ListCount Then
For Each tmp In .ItemsSelected
strC3 = strC3 & "Partner1='" & .ItemData(tmp) & "' or "
Next tmp
strC3 = Left$(strC3, Len(strC3) - 4)
End If
End With
If strC1 <> "" And strC2 <> "" And strC3 <> "" Then
strSQL = strSQL & " where (" & strC1 & ") and (" & strC2 & ") and (" & strC2 & ")"
ElseIf strC1 <> "" Then
strSQL = strSQL & " where " & strC1
ElseIf strC2 <> "" Then
strSQL = strSQL & " where " & strC2
ElseIf strC3 <> "" Then
strSQL = strSQL & " where " & strC3
End If
strSQL = strSQL & " GROUP BY [Sales Zahlen].Fondsname ORDER BY Sum([Sales Zahlen].AuM_) DESC;"
'MsgBox strSQL
CurrentDb.QueryDefs("Abfrage1").SQL = strSQL
DoCmd.OpenReport "Bericht1", acViewPreview
End Sub