Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. Private Sub CreateTargetPDF_Click()
  2. Dim strWhere As String
  3. Dim ctl As Control
  4. Dim varItem As Variant
  5. Dim ReportName As String
  6. Dim counter As Byte
  7.  
  8. StartingFolder = BrowseForFolder("\Documents")
  9.  
  10. 'confirm selection
  11. If Me.EmployeeNameList.ItemsSelected.Count = 0 Then
  12. MsgBox "Must select at least 1 Employee"
  13. Exit Sub
  14. End If
  15.  
  16. 'add selected values to string
  17. Set ctl = Me.EmployeeNameList
  18. For Each varItem In ctl.ItemsSelected
  19. strWhere = strWhere & "'" & ctl.ItemData(varItem) & "'" & ","
  20. 'trim trailing comma and '
  21. strWhere = Left(strWhere, Len(strWhere) - 1)
  22. ReportName = Replace(strWhere, "'", "")
  23.  
  24. 'Select report based on Comp Title
  25. Role = CompTitleList.Value
  26. ReportFormat = "Rpt_Target" & Role
  27.  
  28. 'open report
  29. DoCmd.OpenReport ReportFormat, acViewPreview, , "[Emp_FullName] IN(" & strWhere & ")"
  30.  
  31. 'print report
  32. DoCmd.OutputTo acOutputReport, ReportFormat, acFormatPDF, StartingFolder & "/" & ReportName & " - 2017 " & Role & " Target Statement" & ".pdf", False
  33.  
  34. 'Close Report
  35. DoCmd.Close acReport, ReportFormat
  36.  
  37. Next varItem
  38.  
  39. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement