Я не программист, но я создаю базу данных Access для работы.База данных работает нормально, но я изо всех сил пытаюсь экспортировать один важный запрос, чтобы преуспеть.Спасибо за помощь и извините за плохие методы и, возможно, за многие синтаксические ошибки.
Из запроса на объединение, приведенного ниже под названием «Поток обработки до сегодняшнего дня», я создал один запрос для группировки по коду продукта с именем «Поток обработки до сегодняшнего дня».Запрос », затем другой запрос для добавления столбцов для выполнения некоторых вычислений, которые я хочу экспортировать в Excel.
Запрос, который мне нужно экспортировать, называется« Экспорт запроса ».Выглядит это так:
(Продукт / Запас на переработку / Переработка / Использовано / переработано / Новая обработка)
Это вычисляемые поля из данных, полученных в Union Query, а затем сгруппированный запрос.
Вот код запроса объединения:
SELECT DISTINCTROW
Batch.[Production Date], Products.[Rework Family] AS [Product Code],
Batch.[Rework Used] AS [Rework Used TODAY lb 1], Batch.[Support row] AS [Rework Used YESTERDAY lb 1],
Batch.[Support row] AS [Rework Used TODAY lb 2],
Batch.[Support row] AS [Rework Used YESTERDAY lb 2],
Batch.[Support row] AS [New Rework TODAY lb],
Batch.[Support row] AS [New Rework YESTERDAY lb]
FROM Batch INNER JOIN Products ON Batch.[Rework Product] = Products.[Product ID]
WHERE (((Batch.[Production Date])=[Forms]![01 Production Batch Form]![Today Date]))
UNION ALL
SELECT DISTINCTROW
Batch.[Production Date], Products.[Rework Family] AS [Product Code],
Batch.[Support row] AS [Rework Used TODAY lb 1],
Batch.[Rework Used] AS [Rework Used YESTERDAY lb 1],
Batch.[Support row] AS [Rework Used TODAY lb 2],
Batch.[Support row] AS [Rework Used YESTERDAY lb 2],
Batch.[Support row] AS [New Rework TODAY lb],
Batch.[Support row] AS [New Rework YESTERDAY lb]
FROM Batch INNER JOIN Products ON Batch.[Rework Product] = Products.[Product ID]
WHERE (((Batch.[Production Date])<[Forms]![01 Production Batch Form]![Today Date]))
UNION ALL
SELECT DISTINCTROW
Batch.[Production Date], Products.[Rework Family] AS [Product Code],
Batch.[Support column] AS [Rework Used TODAY lb 1],
Batch.[Support column] AS [Rework Used YESTERDAY lb 1],
Batch.[Rework Used 2] AS [Rework Used TODAY lb 2],
Batch.[Support column] AS [Rework Used YESTERDAY lb 2],
Batch.[Support column] AS [New Rework TODAY lb],
Batch.[Support column] AS [New Rework YESTERDAY lb]
FROM Batch INNER JOIN Products ON Batch.[Rework Product 2] = Products.[Product ID]
WHERE (((Batch.[Production Date])=[Forms]![01 Production Batch Form]![Today Date]))
UNION ALL
SELECT DISTINCTROW
Batch.[Production Date], Products.[Rework Family] AS [Product Code],
Batch.[Support column] AS [Rework Used TODAY lb 1],
Batch.[Support column] AS [Rework Used YESTERDAY lb 1],
Batch.[Support column] AS [Rework Used TODAY lb 2],
Batch.[Rework Used 2] AS [Rework Used YESTERDAY lb 2],
Batch.[Support column] AS [New Rework TODAY lb],
Batch.[Support column] AS [New Rework YESTERDAY lb]
FROM Batch INNER JOIN Products ON Batch.[Rework Product 2] = Products.[Product ID]
WHERE (((Batch.[Production Date])=[Forms]![01 Production Batch Form]![Today Date]))
UNION ALL
SELECT DISTINCTROW Batch.[Production Date], Products.[Rework Family] AS [Product Code],
Batch.[Support column] AS [Rework Used TODAY lb 1],
Batch.[Support column] AS [Rework Used YESTERDAY lb 1],
Batch.[Rework Used 2] AS [Rework Used TODAY lb 2],
Batch.[Support column] AS [Rework Used YESTERDAY lb 2],
Batch.[New Rework] AS [New Rework TODAY lb],
Batch.[Support column] AS [New Rework YESTERDAY lb]
FROM Batch INNER JOIN Products ON Batch.Product = Products.[Product ID]
WHERE (((Batch.[Production Date])=[Forms]![01 Production Batch Form]![Today Date]))
UNION ALL
SELECT DISTINCTROW
Batch.[Production Date], Products.[Rework Family] AS [Product Code],
Batch.[Support column] AS [Rework Used TODAY lb 1],
Batch.[Support column] AS [Rework Used YESTERDAY lb 1],
Batch.[Rework Used 2] AS [Rework Used TODAY lb 2],
Batch.[Support column] AS [Rework Used YESTERDAY lb 2],
Batch.[Support column] AS [New Rework TODAY lb],
Batch.[New Rework] AS [New Rework YESTERDAY lb]
FROM Batch INNER JOIN Products ON Batch.Product = Products.[Product ID]
WHERE (((Batch.[Production Date])<[Forms]![01 Production Batch Form]![Today Date]));`
Когда я использую «Запрос объединения» в моем коде для экспорта в Excel, я добавляю # «& и &» # до и последаты, но я получаю номер ошибки 3129. Когда я использую «Запрос на экспорт» в моем коде, я получаю ошибку 3061 Слишком мало параметров, ожидается 1.
вот код запроса на экспорт:
SELECT DISTINCTROW
[Rework Flow until Today].[Product Code],
Sum([Rework Flow until Today].[Rework Used TODAY lb 1]) AS [SumOfRework Used TODAY lb 1],
Sum([Rework Flow until Today].[Rework Used YESTERDAY lb 1]) AS [SumOfRework Used YESTERDAY lb 1],
Sum([Rework Flow until Today].[Rework Used TODAY lb 2]) AS [SumOfRework Used TODAY lb 2],
Sum([Rework Flow until Today].[Rework Used YESTERDAY lb 2]) AS [SumOfRework Used YESTERDAY lb 2],
Sum([Rework Flow until Today].[New Rework TODAY lb]) AS [SumOfNew Rework TODAY lb],
Sum([Rework Flow until Today].[New Rework YESTERDAY lb]) AS [SumOfNew Rework YESTERDAY lb]
FROM [Rework Flow until Today]
GROUP BY [Rework Flow until Today].[Product Code];
Ниже мой VBA код
Dim SQL As String
Dim rs1 As DAO.Recordset
SQL = " One of the queries here "
Set rs1 = CurrentDb.OpenRecordset(SQL, dbOpenSnapshot)
спасибо