How to select correct Snapshot report based on current ECN

aldeb

Registered User.
Local time
Today, 18:30
Joined
Dec 23, 2004
Messages
318
I am trying to save a report in snapshot mode and attached
it to an email. The first piece of code works and picks
up the correct snapshot report.

The second piece of code works but the snapshot report it
picks up is always based on the the first ECN in the
database. What I am wanting it to be is the snapshot report
based on the ECN that is currently selected. I need it
to work with the second piece of code because that is
the email code we are using throughout the database. Can
someone tell me what I need to do to get the second piece
of code to pick up the correct snapshot report based on
whatever ECN that is currently selected?


Code:
On Error GoTo Err_EmailEcn_Click
'Checks for empty field value, it not empty then proceeds
If Not cboECNLookup.Value = "" Then

    Dim stDocName As String

stDocName = "ECNBCNVIPrpt-2"
If InStr(UserGroups(), "admingrp") > 0 Then
DoCmd.RunCommand acCmdSaveRecord
ElseIf InStr(UserGroups(), "entrygrp") > 0 Then
Me.ECN_Analyst.SetFocus
DoCmd.RunCommand acCmdSaveRecord
End If
DoCmd.SendObject acReport, stDocName, "Snapshot Format"


Else: MsgBox "Please select an ECN Number from the drop down list on the left."
End If
Exit_EmailEcn_Click:
    Exit Sub

Err_EmailEcn_Click:
    MsgBox Err.Description
    Resume Exit_EmailEcn_Click
Code:
If Not Forms!ECNBCNVIPfrm!cboECNLookup.Value = "" Then

Dim stDocName As String

stDocName = "ECNBCNVIPrpt-2"
If InStr(UserGroups(), "admingrp") > 0 Then
DoCmd.RunCommand acCmdSaveRecord
ElseIf InStr(UserGroups(), "entrygrp") > 0 Then
Forms!ECNBCNVIPfrm!ECN_Analyst.SetFocus
DoCmd.RunCommand acCmdSaveRecord
End If

DoCmd.OutputTo acOutputReport, "ECNBCNVIPrpt-2", "Snapshot Format", "ECNBCNVIPrpt.snp", , "C:\my documents\ECNBCNVIPrpt.snp", True

       Dim O As Outlook.Application
       Dim m As Outlook.MailItem
       Dim toEmail1 As String
       Dim toEmail2 As String
       Dim ccEmail1 As String
       Dim ccEmail2 As String
       Dim ccEmail3 As String
       Dim bccEmail1 As String
       Dim SL As String, DL As String
       SL = vbNewLine
       DL = SL & SL

Set O = CreateObject("Outlook.Application")
Set m = Outlook.CreateItem(0)

Dim X
Dim Y
toEmail1 = ""
For Each X In Split(Forms!ECNBCNVIPfrm!ECNDetailfrm![Engineering Distribution] & "", vbCrLf)
  If Trim(X & "") > "" Then
    Y = DLookup("LoginName", "FormEngMETbl", "EngME='" & X & "'")
    If Trim(Y & "") > "" Then
      toEmail1 = toEmail1 & Y & "@nmhg.com;"
    End If
  End If
Next
For Each X In Split(Forms!ECNBCNVIPfrm!ECNDetailfrm![MastDistribution] & "", vbCrLf)
  If Trim(X & "") > "" Then
    Y = DLookup("LoginName", "FormMastEngTbl", "MastEng='" & X & "'")
    If Trim(Y & "") > "" Then
      toEmail1 = toEmail1 & Y & "@nmhg.com;"
    End If
  End If
Next
For Each X In Split(Forms!ECNBCNVIPfrm!ECNDetailfrm![FabDistribution] & "", vbCrLf)
  If Trim(X & "") > "" Then
    Y = DLookup("LoginName", "FormFabEngTbl", "FabEng='" & X & "'")
    If Trim(Y & "") > "" Then
      toEmail1 = toEmail1 & Y & "@nmhg.com;"
    End If
  End If
Next
For Each X In Split(Forms!ECNBCNVIPfrm!ECNDetailfrm![PaintDistribution] & "", vbCrLf)
  If Trim(X & "") > "" Then
    Y = DLookup("LoginName", "FormPaintEngTbl", "PaintMe='" & X & "'")
    If Trim(Y & "") > "" Then
      toEmail1 = toEmail1 & Y & "@nmhg.com;"
    End If
  End If
Next
For Each X In Split(Forms!ECNBCNVIPfrm!ECNDetailfrm![Quality Distribution] & "", vbCrLf)
  If Trim(X & "") > "" Then
    Y = DLookup("LoginName", "FormQAEngTbl", "QAEng='" & X & "'")
    If Trim(Y & "") > "" Then
      toEmail1 = toEmail1 & Y & "@nmhg.com;"
    End If
  End If
Next
For Each X In Split(Forms!ECNBCNVIPfrm!ECNDetailfrm![MasterSchedulerDistribution] & "", vbCrLf)
  If Trim(X & "") > "" Then
    Y = DLookup("LoginName", "FormMasterSchedulerTbl", "MasterSchedulers='" & X & "'")
    If Trim(Y & "") > "" Then
      toEmail1 = toEmail1 & Y & "@nmhg.com;"
    End If
  End If
Next
If Forms!ECNBCNVIPfrm!ECNDetailfrm![Materials Distribution] = "Kim Dees" Then
toEmail1 = toEmail1 & "abkdees@nmhg.com;"
End If
If Forms!ECNBCNVIPfrm!ECNDetailfrm![Finance Distribution] = "Shirley Combs" Then
toEmail1 = toEmail1 & "abscombs@nmhg.com;"
End If
If Forms!ECNBCNVIPfrm!ECNDetailfrm![Sped Distribution] = "Jim Taylor" Then
toEmail1 = toEmail1 & "abjtaylo@nmhg.com;"
End If
If Forms!ECNBCNVIPfrm!ECNDetailfrm![Production Scheduling Distribution] = "Kimberly Kulhavy" Then
toEmail1 = toEmail1 & "abkkulhy@nmhg.com;"
End If
If Forms!ECNBCNVIPfrm!ECNDetailfrm![Service Engineering Distribution] = "Mark Hume" Then
toEmail1 = toEmail1 & "abmhume@nmhg.com;"
End If
If Forms!ECNBCNVIPfrm!ECNDetailfrm![ISA Distribution] = "FYI" Then
toEmail1 = toEmail1 & "kelley.johnson@sdi.com;"
End If

ccEmail1 = "abkkulhy@nmhg.com"
ccEmail2 = "abkkulhy@nmhg.com"
ccEmail3 = ""
bccEmail1 = "abajacks@nmhg.com"

m.To = toEmail1
m.CC = ""
m.BCC = bccEmail1
m.Subject = "ECN #  " & Forms!ECNBCNVIPfrm![ECN Number].Value & "; This ECN is ready to be worked"
m.Body = "This ECN is Ready to be worked." & DL & _
       "Form # " & Forms!ECNBCNVIPfrm![ECNBCNVIP ID].Value & DL & _
       "ECN #  " & Forms!ECNBCNVIPfrm![ECN Number].Value & DL & _
       "ECN Description: " & Forms!ECNBCNVIPfrm!ECNDetailfrm![ECN Description].Value & DL & _
       "Comments: " & Forms!ECNBCNVIPfrm!ECNDetailfrm![Comments].Value & DL & _
       "Thank you for your help" & DL & _
       DLookup("ActualName", "ChangeFormUserNameTbl", "LoginName='" & GetCurrentUserName() & "'") & SL & _
       "ECN Analyst"

m.Attachments.Add "c:\my documents\ECNBCNVIPrpt.snp"

m.Display

On Error GoTo Err_CloseForm_Click


    DoCmd.Close acForm, "PopupEcn3"

Exit_CloseForm_Click:
    Exit Sub

Err_CloseForm_Click:
    MsgBox Err.Description
    Resume Exit_CloseForm_Click
End If
 
I would assume that I am not saving the Report based on
which ECN is selected but I do not know how to do that. The
first piece of code will give me the Snapshot report based
on the ECN that is selected. The second will not.
 

Users who are viewing this thread

Back
Top Bottom