【发布时间】:2014-01-31 21:55:55
【问题描述】:
我正在使用带有 VBA SQL 语句的 MS Access 2007 构建一个类模块,以发送保存文件并发送两封不同的电子邮件。我不断收到未为 Status_Tbl 中的字段 MWStatus 定义的变量。我现在对所有代码都视而不见,需要帮助。我在表单后面的模块中有 SQL 语句,它可以工作,但是会减慢表单的速度,所以我正在移动 SQL 语句。我的问题是,为什么 Status_Tbl 中的字段 MWStatus 给我错误“变量未定义”。这是我第一次把SQL语句放到VBA Module中,不知道是不是做对了
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 strSQL As String
Dim strCMCID As String
strCMCID = Me!CMCID_Txt.Value
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 & " ' ; "
'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([DBUsers_Tbl_1.EMail], "John.Vanesler@CommerceBank.com")
ProcEmail = Nz([DBUsers_Tbl.EMail], "John.Vanesler@CommerceBank.com")
If Me!RateExpDate_Txt <= Date + 8 Then
Caution = "STOP Terms Finalized:"
ElseIf ***MWStatus*** = "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
Exit_SendConfirm_Click:
Exit Sub
Err_SendConfirm_Click:
MsgBox Err.Description
Resume Exit_SendConfirm_Click
End Sub
【问题讨论】:
-
你的问题到底是什么......?
-
@Dan 感谢您查看这篇文章。背景故事,我在表单后面的模块中有 SQL 语句,它可以工作,但是减慢了表单的速度,所以我正在移动 SQL 语句。我的问题是,为什么 Status_Tbl 中的字段 MWStatus 给我错误“变量未定义”。这是我第一次把SQL语句放到VBA Module中,不知道做对了没有。
-
@Dan 我不认为我把你的名字写对了,所以我又做了一次。很抱歉,如果您有两次联系。
-
别担心,@user3258917。
标签: sql ms-access ms-access-2007 vba