gpt4 book ai didi

sql - 访问 2007 VBA SQL 选择错误 "Item not found in this collection"

转载 作者:行者123 更新时间:2023-12-02 04:37:50 25 4
gpt4 key购买 nike

修复错误后返回,现在又是一个新错误。我在 Access 2007 中使用 VBA 创建了一个 SQL 语句,但出现错误“在此集合中未找到项目” 字段确实存在于表中并且拼写正确。我什至将 SQL 语句复制到查询中并且它起作用了。我假设错误出在这部分代码上

Dim strCMCID As Long  ' (it's a Key field AutoNumber) 
strCMCID = Me!CMCID_Txt

"WHERE Commitments_Tbl.CMCID = " & strCMCID & "" 

下面发布了完整的代码。这是我第一次使用 VBA 放入 SQL 语句。我想要做的是让 SQL 语句从当前表单的特定记录中提取两个电子邮件地址。

Public Sub SendConfirm()
On Error GoTo Err_SendConfirm_Click

Dim Borrower As String, LOEmail As String, ProcEmail As String, ClsEmail As String, Caution As String, LNumber As Long, TheFile As String, TheName As String

'SQL Statement to get Processor and Closer email
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strCMCID As Long 'AutoNumber
Dim strMWS As String
Dim strProcEM As String
Dim StrClsEM As String

strCMCID = Me!CMCID_Txt 'AutoNumber
strSQL = "SELECT Commitments_Tbl.CMCID, Status_Tbl.MWStatus, DBUsers_Tbl.EMail, DBUsers_Tbl_1.EMail " & _
"FROM ((Commitments_Tbl LEFT JOIN Status_Tbl ON Commitments_Tbl.LoanNumber = Status_Tbl.LoanNumber) LEFT JOIN DBUsers_Tbl AS DBUsers_Tbl_1 ON Status_Tbl.Processor = DBUsers_Tbl_1.MWName) LEFT JOIN DBUsers_Tbl ON Status_Tbl.Closer = DBUsers_Tbl.MWName " & _
"WHERE Commitments_Tbl.CMCID = " & strCMCID & ""

Set dbs = CurrentDb
Set rst = CurrentDb.OpenRecordset(strSQL)
strMWS = rst!MWStatus
strProcEM = Nz(rst!DBUsers_Tbl.EMail, "John.Doe@CWork.com")
StrClsEM = Nz(rst!DBUsers_Tbl_1.EMail, "John.Doe@Work.com")

'Message Box
Dim Msg, Style, Title, Response

LOEmail = Me!OrigID_Cbo.Column(3)
Borrower = Me!BorrNameL_Txt
LNumber = Nz(Me!LoanNumber_Txt, 0)

Msg = "Do you want to send an e-mail to Set_up?"
Style = vbYesNo
Title = "Cancel Set-Up E-Mail"
Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then
GoTo line3
Else
GoTo line4
End If

line3:
TheName = "" & Borrower & " " & LNumber & ""
TheFile = "P:\mortgage\prodcenters\LOAN ITEMS (SW)\_RateLocks_and_Changes\" & TheName & ".rtf"

DoCmd.OutputTo acOutputReport, "Confirmation_Email2", acFormatRTF, TheFile, False

If Nz(Me!InvestorID_Cbo, "Blank") = "Blank" Then
DoCmd.SendObject , , , "CommerceMortgage@CommerceBank.com", , , "New Lock: " & Borrower & ": " & LNumber, "A rate lock confirmation has been saved down to the server at P:\mortgage\prodcenters\LOAN ITEMS (SW)\_RateLocks_and_Changes as a word document with the same name and loan number as that is the subject line of this email. Please upload it into the GDR.", -1
Else
DoCmd.SendObject , , , "CommerceMortgage@CommerceBank.com", , , "Term Change" & ": " & Borrower & ": " & LNumber, "A rate lock confirmation has been saved down to the server at P:\mortgage\prodcenters\LOAN ITEMS (SW)\_RateLocks_and_Changes as a word document with the same name and loan number as that is the subject line of this email. Please upload it into the GDR.", True
End If

line4:
ClsEmail = Nz(StrClsEM, "John.Doe@Work.com")
ProcEmail = Nz(strProcEM, "John.Doe@Work.com")
If Me!RateExpDate_Txt <= Date + 8 Then
Caution = "STOP Terms Finalized:"
ElseIf strMWS = "Closing" And Me!RateExpDate_Txt >= Date + 8 Then
Caution = "STOP:"
Else
Caution = ""
End If
If Me!InvestorID_Cbo = "" Then
DoCmd.SendObject acSendReport, "Confirmation_Email", "SnapshotFormat(*.snp)", LOEmail, ProcEmail & ";" & ClsEmail, , Caution & "New Lock: " & Borrower & ": " & LNumber, , True
Else
DoCmd.SendObject acSendReport, "Confirmation_Email", "SnapshotFormat(*.snp)", LOEmail, ProcEmail & ";" & ClsEmail, , Caution & " " & "Term Change" & ": " & Borrower & ": " & LNumber, , True
End If
rst.Close
Set rst = Nothing
Set dbs = Nothing

Exit_SendConfirm_Click:
Exit Sub

Err_SendConfirm_Click:
MsgBox Err.Description
Resume Exit_SendConfirm_Click

End Sub

最佳答案

如果我们在 Access 中创建一个查询,从两个不同的表中提取两个具有相同名称的字段,那么 Access 会将结果列命名为 Table1.FieldTable2.Field消除歧义。当使用“bang (!) 表示法”引用 Recordset 中的那些字段时,您必须将整个字段名称放在方括号中。例如,在您的情况下,您需要使用

rst![DBUsers_Tbl.EMail]

代替

rst!DBUsers_Tbl.EMail

关于sql - 访问 2007 VBA SQL 选择错误 "Item not found in this collection",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21587672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com