SQL中的MS Access筛选器记录集

问题描述 投票:0回答:1

我有一个MS Access模块​​,可在HTML表中为我们公司的供应商创建Outlook电子邮件。我可以使该模块为每个客户创建一封电子邮件,但是我无法获取要过滤到每个公司的数据。例如,该模块为“供应商A”创建电子邮件,但仍在该电子邮件中显示“供应商B”和“供应商C”结果。我目前的尝试是打开一个记录集并将其用作SQL条件,尽管我不断收到错误“没有为一个或多个必需参数提供值”。非常感谢您对我做错事的帮助或指示。


Dim olApp As Outlook.Application
Dim objMail As Outlook.MailItem
Dim myRecipient As Outlook.Recipient
Dim strMsg As String
Dim strbody As String
Dim sqlmsg As String
Dim i As Integer
Dim rowColor As String
Dim strsup As String
Dim supfilter As DAO.Recordset
Dim db As DAO.Database
Dim Maillist As DAO.Recordset

DoCmd.SetWarnings False
Set db = CurrentDb

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set Maillist = db.OpenRecordset("P086 - Email OOR")

sqlmsg = "SELECT [P086 -  Supplier Open Order Report].[Purchase Order ID], [P086 -  Supplier Open Order Report].[PO#] AS [STC Job#], Format([Date],""mm/dd/yyyy"") AS [Issued Date], [P086 -  Supplier Open Order Report].Supplier, [P086 -  Supplier Open Order Report].Quantity, [P086 -  Supplier Open Order Report].DeliveryDate AS [Delivery Date], [P086 -  Supplier Open Order Report].StatDate AS [Stat Date], [P086 -  Supplier Open Order Report].[Till Delivery], [P086 -  Supplier Open Order Report].[Quantity In]" _
        & " From [P086 -  Supplier Open Order Report]" _
        & " WHERE ((([P086 -  Supplier Open Order Report].Supplier) = " & "" & Maillist.Fields("Supplier") & "" & "))" _
        & " ORDER BY [P086 -  Supplier Open Order Report].DeliveryDate;"


rs.Open sqlmsg, CurrentProject.Connection, adOpenKeyset, adLockOptimistic 'No value given for one or more required parameters error happens here


strMsg = "<table border='1' cellpadding='3' cellspacing='3' style='border-collapse: collapse' bordercolor='#111111' width='800'>" & _
"<tr>" & _
"<td bgcolor='#B0C4DE'>&nbsp;<b>Purchase Order</b></td>" & _
"<td bgcolor='#B0C4DE'>&nbsp;<b>STC Job#</b></td>" & _
"<td bgcolor='#B0C4DE'>&nbsp;<b>Issue Date</b></td>" & _
"<td bgcolor='#B0C4DE'>&nbsp;<b>Supplier</b></td>" & _
"<td bgcolor='#B0C4DE'>&nbsp;<b>Quantity</b></td>" & _
"<td bgcolor='#B0C4DE'>&nbsp;<b>Quantity Received</b></td>" & _
"<td bgcolor='#B0C4DE'>&nbsp;<b>Delivery Date</b></td>" & _
"<td bgcolor='#B0C4DE'>&nbsp;<b>Stat Date</b></td>" & _
"<td bgcolor='#B0C4DE'>&nbsp;<b>Days Till Delivery</b></td>" & _
"</tr>"

i = 0

Do While Not rs.EOF

If (i Mod 2 = 0) Then
rowColor = "<td bgcolor='#FFFFFF'>&nbsp;"
Else
rowColor = "<td bgcolor='#E1DFDF'>&nbsp;"
End If

strMsg = strMsg & "<tr>" & _
rowColor & rs.Fields("Purchase Order ID") & "</td>" & _
rowColor & rs.Fields("STC Job#") & "</td>" & _
rowColor & rs.Fields("Issued Date") & "</td>" & _
rowColor & rs.Fields("Supplier") & "</td>" & _
rowColor & rs.Fields("Quantity") & "</td>" & _
rowColor & rs.Fields("Quantity In") & "</td>" & _
rowColor & rs.Fields("Delivery Date") & "</td>" & _
rowColor & rs.Fields("Stat Date") & "</td>" & _
rowColor & rs.Fields("Till Delivery") & "</td>" & _
"</tr>"

rs.MoveNext
Maillist.MoveNext
i = i + 1
Loop

strbody = Chr(12) & "The Raw Material Auto Order Screen Must Have the 5000 Serial Number Inserted To Be Remove From This Alert." & _
             Chr(12) & "Raw Material QM34 Process Sheets Required For All Inventory Purchases. Stock Number(s) Are Provided In This Email."

strMsg = strMsg & "</table>" & strbody
Set olApp = Outlook.Application
Set Maillist = db.OpenRecordset("P086 - Email OOR")

Do Until Maillist.EOF

Set objMail = olApp.CreateItem(olMailItem)
objMail.To = Maillist("emailaddress")

With objMail
.BodyFormat = olFormatHTML
.HTMLBody = "<Font size =""3"">" & strMsg & "</font>"
.Subject = "Supplier Open Order Report " & Date
'.Send 'if you want to send it directly without displaying on screen
.Display ' to display on screen before send
End With
Maillist.MoveNext
Loop

Set olApp = Nothing
Set objMail = Nothing

End Function
ms-access access-vba
1个回答
0
投票

文本类型字段的标准需要定界符。选项是撇号或双引号。我更喜欢撇号,因为它更易于阅读。日期/时间字段将需要#定界符。

& " WHERE [P086 - Supplier Open Order Report].Supplier = '" & Maillist!Supplier & "'" _

不需要所有这些括号,不需要包含空字符串,引用字段的替代语法。

有关更多信息,请查看INSERT INTO - errors, but allows input into table

© www.soinside.com 2019 - 2024. All rights reserved.