I have two tables in my database that are linked. One is a Branch listing that consists of only 3 fields, BranchID (autonumber) BranchName and OpenClosed. The other table is individual account records which are associated to a Branch (in the branch table). I have added code to a button on a form so that when a branch closed, it will mark the current branch account as Inactive, send an email, and update the Branch table for that Branch as closed. The last piece of code that I want to add to the button is to do a search on all of the accounts in the account table to find if there are any other open accounts for that Branch that is being closed...and to just display them. My code works perfect up to that 2nd SQL query, then i get an error. Not sure if the syntax is incorrect or if I am just not doing it right. This is the first time that I've ever used SQL in code. But I don't know of any other way to do this. Any help would be GREATLY appreciated!! Here is my code:
Private Sub Command18_Click()
Dim statuschange As String
Dim emailrec As String
Dim title As String
Dim title2 As String
Dim tmpLoanOfficer As String
Dim tmpBranchName As String
Dim tmpMachID As String
Dim tmpImageID As String
Dim tmptype As String
Dim tmpclosed As String
Dim SQL2 As String
tmpclosed = "Closed"
tmptype = Me![Last Name]
tmpBranchName = Me![BRANCH NAME]
tmpMachID = Me![CUST ID (MACH30)]
tmpImageID = Me![IMAGE ID]
tmpLoanOfficer = Me![LOAN OFFICER]
Const CR = vbCrLf & vbCrLf
Const CR2 = vbCrLf
title = "Deactivate Branch Account"
title2 = "Deactivate Loan Officer Account"
statuschange = "Inactive"
ActiveStatus = statuschange
DEACTIVATION_DATE = Date
DEACTIVATION_DATE.Visible = True
DeactivatedBy = CurrentUser
SQL1 = "UPDATE tblBranch " & _
"SET tblBranch.OpenClosed = '" & tmpclosed & "' " & _
"WHERE tblBranch.BranchName = '" & tmpBranchName & "'"
SQL2 = "SELECT tblCredcoAcct.Loan_Officer, tblCredcoAcct.Branch_Name " & _
"FROM tblCredcoAcct " & _
"WHERE tblCredcoAcct.Branch_Name = '" & tmpBranchName & "'"
If tmptype = "MAIN BRANCH" Then
DoCmd.SendObject acSendNoObject, , , "Tempemail@email.com", , , title, "Please deactivate the following Branch Account as this branch has been closed:" + CR + tmpBranchName + CR2 + "Mach ID: " + tmpMachID + CR2 + "Image ID: " + tmpImageID, True
DoCmd.RunSQL SQL1
DoCmd.RunSQL SQL2
Else
DoCmd.SendObject acSendNoObject, , , "Tempemail@email.com", , , title2, "Please deactivate the following Loan Officer Account as this Loan Officer has been terminated:" + CR + tmpLoanOfficer + CR2 + "Branch: " + tmpBranchName + CR2 + "Image ID: " + tmpImageID, True
End If
End Sub
Private Sub Command18_Click()
Dim statuschange As String
Dim emailrec As String
Dim title As String
Dim title2 As String
Dim tmpLoanOfficer As String
Dim tmpBranchName As String
Dim tmpMachID As String
Dim tmpImageID As String
Dim tmptype As String
Dim tmpclosed As String
Dim SQL2 As String
tmpclosed = "Closed"
tmptype = Me![Last Name]
tmpBranchName = Me![BRANCH NAME]
tmpMachID = Me![CUST ID (MACH30)]
tmpImageID = Me![IMAGE ID]
tmpLoanOfficer = Me![LOAN OFFICER]
Const CR = vbCrLf & vbCrLf
Const CR2 = vbCrLf
title = "Deactivate Branch Account"
title2 = "Deactivate Loan Officer Account"
statuschange = "Inactive"
ActiveStatus = statuschange
DEACTIVATION_DATE = Date
DEACTIVATION_DATE.Visible = True
DeactivatedBy = CurrentUser
SQL1 = "UPDATE tblBranch " & _
"SET tblBranch.OpenClosed = '" & tmpclosed & "' " & _
"WHERE tblBranch.BranchName = '" & tmpBranchName & "'"
SQL2 = "SELECT tblCredcoAcct.Loan_Officer, tblCredcoAcct.Branch_Name " & _
"FROM tblCredcoAcct " & _
"WHERE tblCredcoAcct.Branch_Name = '" & tmpBranchName & "'"
If tmptype = "MAIN BRANCH" Then
DoCmd.SendObject acSendNoObject, , , "Tempemail@email.com", , , title, "Please deactivate the following Branch Account as this branch has been closed:" + CR + tmpBranchName + CR2 + "Mach ID: " + tmpMachID + CR2 + "Image ID: " + tmpImageID, True
DoCmd.RunSQL SQL1
DoCmd.RunSQL SQL2
Else
DoCmd.SendObject acSendNoObject, , , "Tempemail@email.com", , , title2, "Please deactivate the following Loan Officer Account as this Loan Officer has been terminated:" + CR + tmpLoanOfficer + CR2 + "Branch: " + tmpBranchName + CR2 + "Image ID: " + tmpImageID, True
End If
End Sub