我正在开发一个数据库,该数据库已经根据用户输入表单的日期范围发送了两份销售报告。但是,我正在尝试添加另一个报表,该报表将根据销售人员的ID从表单中输出。但是,我无法弄清楚将where where语句放在哪里说“WHERE TERRITORY =”& rs.fields(1),这是我需要使规范等于,如果这是有道理的。这是我的代码。对此有任何帮助非常感谢。
** FinalFormWithGauges的行是我特别谈论的那个
Dim rs As DAO.Recordset
Dim fld As DAO.Field
Dim territory As String
Dim strSQL As String
Dim strSQL2 As String
Dim strSQL3 As String
Dim strQry As String
Dim qdf As QueryDef
Dim qdf2 As QueryDef
Dim dbs As Database
Dim i As Integer
Dim timestamp As String
DoCmd.OpenForm "Sales Email"
Forms![Sales Email]![FromDate].SetFocus
timestamp = Format(Forms![Sales Email]![FromDate].Value, "mm-yyyy")
Set rs = DBEngine(0)(0).OpenRecordset("KNOXLIVE_Engineers_Test")
For Each fld In rs.Fields
Do While Not rs.EOF
territory = rs.Fields(1)
Set dbs = CurrentDb
strSQL = "SELECT * FROM 001_SALES_OUTPUT_FOR_CURRENT_MONTH WHERE TERRITORY = """ & rs.Fields(1) & """"
strSQL2 = "SELECT * FROM CURRENT_OPEN_ORDERS WHERE TERRITORY = """ & rs.Fields(1) & """"
'strSQL3 = "SELECT * FROM FinalFormWithGauges WHERE TERRITORY = """ & rs.Fields(1) & """"
'MsgBox (strSQL)
Set qdf = dbs.CreateQueryDef("TheNewQueryDef", strSQL)
DoCmd.OutputTo acOutputQuery, "TheNewQueryDef", acFormatXLS, "\\cletus\data\accounting\Regional Sales Reporting\Monthly Sales Database Files By Month\Monthly Sales for " & territory & " " & timestamp & ".xls", False
CurrentDb.QueryDefs.Delete qdf.Name
Set qdf2 = dbs.CreateQueryDef("TheNewQueryDef", strSQL2)
DoCmd.OutputTo acOutputQuery, "TheNewQueryDef", acFormatXLS, "\\cletus\data\accounting\Regional Sales Reporting\Monthly Sales Database Files By Month\Current Open Orders for " & territory & " " & timestamp & ".xls", False
CurrentDb.QueryDefs.Delete qdf.Name
'Set gdf3 = dbs.CreateQueryDef("TheNewQueryDef", strSQL3)
DoCmd.OutputTo acOutputForm, "FinalFormWithGauges", acFormatPDF, "\\cletus\data\accounting\Regional Sales Reporting\Monthly Sales Database Files By Month\Actual Sales vs Budget for " & territory & " " & timestamp & ".PDF", False**
'CurrentDb.QueryDefs.Delete qdf.Name