我正在使用Office 365,并尝试从Access数据库创建HTML电子邮件。我想生成一个表,该表遍历2个记录集。第一个记录集是显示“问题”的查询,第二个记录集是显示两者之间存在一对多关系的问题对策的查询。这就是我要显示表格的方式:
<TABLE>
<TH>Header from Access Table 1 – issue #1</TH>
<TR>Row from Access Table 1– issue #1</TR>
<TH>Header from Access Table 2 – CM # 1</TH>
<TR>Row from Access Table 2 – CM # 1</TR>
</TABLE>
<TABLE>
<TH>Header from Access Table 1 – issue #2</TH>
<TR>Row from Access Table 1– issue #2</TR>
<TH>Header from Access Table 2 – CM # 2</TH>
<TR>Row from Access Table 2 – CM # 2</TR>
</TABLE>
但是我得到:
<TABLE>
<TH>Header from Access Table 1 – issue #1</TH>
<TR>Row from Access Table 1– issue #1</TR>
</TABLE>
<TABLE>
<TH>Header from Access Table 1 – issue #2</TH>
<TR>Row from Access Table 1– issue #2</TR>
</TABLE>
<TABLE>
<TH>Header from Access Table 2 – CM # 2</TH>
<TR>Row from Access Table 2 – CM # 2</TR>
</TABLE>
有人可以指出正确的方向以使我的代码正确循环吗?
strSQL2 = "SELECT * FROM qryZoneIssue " & _
" WHERE qryZoneIssue.ZoneMeetingID = " & HoldMeetingID
'*********** display issues & CMs
Set rs2 = CurrentDb.OpenRecordset(strSQL2, dbOpenDynaset)
rs2.MoveFirst
Do While Not rs2.EOF
strBody2 = strBody2 & "<TABLE Border=""1"", Cellspacing=""0""><TR>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">No. </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">KPI </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">Ranking </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">RPS Started </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">Issue Details </p></Font></TH>" & _
"</TR>"
' add the data to the table
strBody2 = strBody2 & "<TR>" & _
"<TD align=center width=""10%"">" & rs2.Fields![ZoneIssueNo].Value & "</TD>" & _
"<TD align=center width=""15%"">" & rs2.Fields![ZoneKPI].Value & "</TD>" & _
"<TD align=center width=""10%"">" & rs2.Fields![ZoneRankID].Value & "</TD>" & _
"<TD align=center width=""15%"">" & rs2.Fields![RPSStarted].Value & "</TD>" & _
"<TD align=left width=""50%"">" & rs2.Fields![ZoneIssue].Value & "</TD>" & _
"</TR>"
strSQL3 = "SELECT * FROM qryZonePermCM " & _
" WHERE qryZonePermCM.ZoneMeetingID = " & HoldMeetingID & "AND ZoneIssueID = " & rs2.Fields![ZoneIssueID].Value
strBody2 = strBody2 & "</table>"
rs2.MoveNext
Loop
Set rs3 = CurrentDb.OpenRecordset(strSQL3, dbOpenDynaset)
rs3.MoveFirst
Do While Not rs3.EOF
strBody2 = strBody2 & "<TABLE Border=""1"", Cellspacing=""0""><TR>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">CM Details </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">Responsible </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">Target Date </p></Font></TH>" & _
' add the data to the table
strBody2 = strBody2 & "<TR>" & _
"<TD align=left width=""40%"">" & rs3.Fields![CMDetails].Value & "</TD>" & _
"<TD align=center width=""15%"">" & rs3.Fields![Responsible].Value & "</TD>" & _
"<TD align=center width=""10%"">" & rs3.Fields![TargetDate].Value & "</TD>" & _
"</TR>"
strBody2 = strBody2 & "</table>"
rs3.MoveNext
Loop
rs3.Close
考虑:
strSQL2 = "SELECT * FROM qryZoneIssue WHERE ZoneMeetingID = " & HoldMeetingID
'*********** display issues & CMs
Set rs2 = CurrentDb.OpenRecordset(strSQL2, dbOpenDynaset)
rs2.MoveFirst
Do While Not rs2.EOF
strBody2 = strBody2 & "<TABLE Border=""1"", Cellspacing=""0""><TR>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">No. </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">KPI </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">Ranking </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">RPS Started </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">Issue Details </p></Font></TH>" & _
"</TR>"
' add the data to the table
strBody2 = strBody2 & "<TR>" & _
"<TD align=center width=""10%"">" & rs2.Fields![ZoneIssueNo].Value & "</TD>" & _
"<TD align=center width=""15%"">" & rs2.Fields![ZoneKPI].Value & "</TD>" & _
"<TD align=center width=""10%"">" & rs2.Fields![ZoneRankID].Value & "</TD>" & _
"<TD align=center width=""15%"">" & rs2.Fields![RPSStarted].Value & "</TD>" & _
"<TD align=left width=""50%"">" & rs2.Fields![ZoneIssue].Value & "</TD>" & _
"</TR>"
strSQL3 = "SELECT * FROM qryZonePermCM WHERE ZoneMeetingID = " & HoldMeetingID & " AND ZoneIssueID = " & rs2!ZoneIssueID
Set rs3 = CurrentDb.OpenRecordset(strSQL3, dbOpenDynaset)
strBody2 = strBody2 & "<TR>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">CM Details </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">Responsible </p></Font></TH>" & _
"<TH Bgcolor=""#2B3856"", Align=""Center""><Font Color=#FFFFFF><b><p style=""font-size:14px"">Target Date </p></Font></TH>" & _
"</TR>"
Do While Not rs3.EOF ' add the data to the table
strBody2 = strBody2 & "<TR>" & _
"<TD align=left width=""40%"">" & rs3.Fields![CMDetails].Value & "</TD>" & _
"<TD align=center width=""15%"">" & rs3.Fields![Responsible].Value & "</TD>" & _
"<TD align=center width=""10%"">" & rs3.Fields![TargetDate].Value & "</TD>" & _
"</TR>"
rs3.MoveNext
Loop
strBody1 = strBody1 & strBody2 & "</table>"
strBody2 = ""
rs3.Close
rs2.MoveNext
Loop
rs2.Close
'set HTML body to strBody1