Ich muss eine Excel-Anlage erstellen, die für eine Teilmenge der Tabelle, die ich verwende, wäre. Wenn der Code also jeden Vertriebsmitarbeiter durchläuft (in diesem Fall), müsste er eine E-Mail mit den für ihn relevanten Informationen in dem unten formatierten E-Mail-Text senden, aber auch eine Excel-Tabelle mit den gleichen Informationen in einer Massenweise, sortiert nach Status.Access VB - Temp Erstellung von Tabellen und E-Mail-Anhang
Ich denke, dass dies getan werden müsste, indem man eine temporäre Tabelle oder etwas Ähnliches schafft und es löscht, aber ich bin ein wenig verloren, wo ich etwas so setzen würde oder sogar, was es enden würde sieht aus wie.
Hier ist, was ich bisher habe. Im Grunde genommen alles, um es mit Kategorien und Zeug auf die E-Mail zu setzen. Ich denke, es wird am Ende auf HTML umgestellt, aber das ist weder hier noch dort. Wie auch immer, danke im voraus:
Function SendNotification()
Dim OutApp As Object
Dim OutMail As Object
Dim rs As DAO.Recordset
Dim db As Database
Dim sql, sMsg, sPrevTerritory, sPrevEmail, sCurrentTerritory, sPrevRep, sCurrentRep, sKrullj1, sImgPath, sTherapy As String
Dim iNotRecieved, iCompleted, iWorksheetGenerated, iReconciled As Integer
iNotRecieved = 0
iCompleted = 0
iWorksheetGenerated = 0
iReconciled = 0
sKrullj1 = "[email protected]"
'Set Outlook Variables
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set db = CurrentDb
sql = "select * from [MT + Emails] Order By Territory,[Status] desc where Therapy = 'Peripheral' and [Loc Type] = 'Account'"
Set rs = db.OpenRecordset(sql, dbOpenDynaset, dbSeeChanges)
sPrevTerritory = rs!Territory
sPrevRep = rs![Employee Name]
sPrevEmail = Nz(rs![Employee Email Address], GetUserName() & "@placeofemployment.com")
sTherapy = rs!Therapy
sMsg = "Hello," & vbLf & vbLf & "Here is an update on your Cycle Count(s)." & vbLf & vbLf
Do While Not rs.EOF
If sPrevTerritory <> rs!Territory Then
sMsg = sMsg & "Regards," & vbLf & vbLf & "Customer Care"
With OutMail
.To = sPrevEmail
'.To = sKrullj1
.BCC = GetUserName() & "@placeofemployment.com"
.Sentonbehalfofname = "[email protected]"
'.Subject = "Cycle Count Update"
.Subject = "Cycle Count Update - " & sPrevTerritory & "" & sPrevRep
.Body = sMsg
.Send
'.Display
End With
sMsg = "Hello," & vbLf & vbLf & "Here is an update on your Cycle Count(s)." & vbLf & vbLf
sPrevEmail = Nz(rs![Employee Email Address], GetUserName() & "@placeofemployment.com")
sPrevTerritory = rs!Territory
sPrevRep = rs![Employee Name]
iNotRecieved = 0
iCompleted = 0
iWorksheetGenerated = 0
iReconciled = 0
End If
sCurrentEmail = Nz(rs![Employee Email Address], GetUserName() & "@placeofemployment.com")
If rs![Status] = "Not Recieved" And iNotRecieved = 0 Then
iNotRecieved = 1
sMsg = sMsg & "The following Cycle Count (s) have not been received:" & vbLf & vbLf
ElseIf rs![Status] = "Completed" And iCompleted = 0 Then
iCompleted = 1
sMsg = sMsg & "The following Cycle Count(s) have been completed:" & vbLf & vbLf
ElseIf rs![Status] = "Worksheet Generated" And iWorksheetGenerated = 0 Then
iWorksheetGenerated = 1
sMsg = sMsg & "The following Cycle Count(s) have been receieved and are pending reconciliation:" & vbLf & vbLf
ElseIf rs![Status] = "Reconcilied - Pending SAP Processing" And iReconciled = 0 Then
iReconciled = 1
sMsg = sMsg & "The following Cycle Count(s) have been recieved, reconciled, and are pending SAP processing:" & vbLf & vbLf
End If
sMsg = sMsg & vbTab & "Status: " & rs![Status] & vbLf _
& vbTab & "Location: " & rs![Location] & vbLf _
& vbTab & "Location Name: " & rs![Location Name] & vbLf _
& vbTab & "Territory: " & rs![Territory Name] & vbLf _
& vbTab & "District: " & rs![District Name] & vbLf _
& vbTab & "CC Master ID: " & rs![ID] & vbLf & vbLf _
rs.MoveNext
Loop
sMsg = sMsg & "Regards," & vbLf & vbLf & "Customer Care"
With OutMail
.To = sPrevEmail
'.To = sKrullj1
.BCC = GetUserName() & "@placeofemployment.com"
.Sentonbehalfofname = "[email protected]"
'.Subject = "Cycle Count Update"
.Subject = "Cycle Count Update - " & sPrevTerritory & "" & sRep
.Body = sMsg
.Send
'.Display
End With
' Reset Outlook variables
Set OutMail = Nothing
Set OutApp = Nothing
End Function