Dim strTabel As String
Dim strSQL As String
strTabel = "VoorraadNederweert"
strSQL = "Select * From " & strTabel & vbCrLf _
& "Where ((([Datum])>=#" & Me.Startdatum.Value & "# And ([Datum])<=#" & Me.Einddatum.Value & "#)" _
& "And ([LeverancierID]=" & Me.Leverancier_NW & ")" _
& "And ([ProductID]=" & Me.ProductID_NW & "));"
Me.RecordSource = strSQL
Me.Requery
Dim strSQL1 As String
Dim strSQL2 As String
Dim sBeginDatum As Date, sEindDatum As Date
Dim iBegin As Double, eEind As Double
Dim rst As DAO.Recordset
sBeginDatum = CDate(Me.Startdatum.Value)
sEindDatum = CDate(Me.Einddatum.Value)
iBegin = CDbl(sBeginDatum)
eEind = CDbl(sEindDatum)
strSQL1 = "SELECT Sum(AlleOrders.Hoeveelheid) AS Aantal, Leverancier.Leverancier, Producten.Product, AlleOrders.LocatieID, AlleOrders.LeverancierID, AlleOrders.ProductID " & _
"FROM Leverancier INNER JOIN (Bedrijfsonderdelen INNER JOIN (Producten INNER JOIN AlleOrders ON Producten.ProductID = AlleOrders.ProductID) ON Bedrijfsonderdelen.LocatieID = AlleOrders.LocatieID) ON Leverancier.LeverancierID = AlleOrders.LeverancierID " & _
"WHERE ((AlleOrders.Datum Between cDate(" & iBegin & ") And cDate(" & eEind & ")) And (AlleOrders.ProductID=" & Me.ProductID_NW & ") And (AlleOrders.LocatieID<>2) And (AlleOrders.LeverancierID=7)) " & _
"GROUP BY Leverancier.Leverancier, Producten.Product, AlleOrders.LocatieID, AlleOrders.LeverancierID, AlleOrders.ProductID;"
Set rst = CurrentDb.OpenRecordset(strSQL1)
If rst.RecordCount > 0 Then
Me.InternLev.Value = rst.Fields("Aantal").Value
Else
Me.InternLev.Value = 0
End If
strSQL2 = "SELECT Sum(AlleOrders.Hoeveelheid) AS Aantal, Leverancier.Leverancier, Producten.Product, AlleOrders.LocatieID, AlleOrders.LeverancierID, AlleOrders.ProductID " & _
"FROM Leverancier INNER JOIN (Bedrijfsonderdelen INNER JOIN (Producten INNER JOIN AlleOrders ON Producten.ProductID = AlleOrders.ProductID) ON Bedrijfsonderdelen.LocatieID = AlleOrders.LocatieID) ON Leverancier.LeverancierID = AlleOrders.LeverancierID " & _
"WHERE ((AlleOrders.Datum Between cDate(" & iBegin & ") And cDate(" & eEind & ")) And (AlleOrders.ProductID=" & Me.ProductID_NW & ") And (AlleOrders.LocatieID=2) And (AlleOrders.LeverancierID Between 5 And 9)) " & _
"GROUP BY Leverancier.Leverancier, Producten.Product, AlleOrders.LocatieID, AlleOrders.LeverancierID, AlleOrders.ProductID;"
Set rst = CurrentDb.OpenRecordset(strSQL2)
If rst.RecordCount > 0 Then
Me.InternOnt.Value = rst.Fields("Aantal").Value
Else
Me.InternOnt.Value = 0
End If