Public Function ConcatCourses(thisPerson As String) As String
Dim rst As DAO.Recordset
Dim strResults As String
Dim strSql As String
strSql = "select people.course from people where person='" & thisPerson & "';"
' strSql = "select course from people"
'open a recordset based on the query
Set rst = CurrentDb.OpenRecordset(strSql, dbOpenDynaset)
'loop though the query and build the results string
'on the first time through the loop do not add the delimiter
While Not rst.EOF
If Len(strResults) > 0 Then
strResults = strResults & "," & rst.Fields(0)
Else
strResults = rst.Fields(0)
End If
rst.MoveNext
Wend
'return the results string
ConcatCourses = strResults
End Function
Sub SplitMergeLetter()
' splitter Macro modified to save individual letters with
' information from data source. The filename data must be added to
' the top of the merge letter - see web article.
Dim sName As String
Dim docName As String
Dim Letters As String
Dim Counter As Long
Dim oDoc As Document
Dim oNewDoc As Document
Set oDoc = ActiveDocument
'oDoc.Save
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
sName = Selection
docName = "J:\Memos\Single Course\" & sName & ".pdf"
oDoc.Sections.First.Range.Cut
Set oNewDoc = Documents.Add
'Documents are based on the Normal template
'To use an alternative template follow the link.
With Selection
.Paste
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With
oNewDoc.SaveAs FileName:=docName, _
FileFormat:=wdFormatPDF, _
AddToRecentFiles:=False
oNewDoc.Saved = True
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
'oDoc.Close wdDoNotSaveChanges
End Sub
Private sub cmdCreatePdfs_Click()
'this is the half the biggie, sewing it all together
Dim db As Database
Dim rs As Recordset
Dim rs1 As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("select distinct [learner id] from qryDelinquencies", dbOpenDynaset, dbSeeChanges)
rs.MoveLast
rs.MoveFirst
Do Until rs.EOF = True
Set rs1 = db.OpenRecordset("Select * from qryLearnerDetails where [Learner ID] = " & Chr(34) & rs![Learner ID] & Chr(34), dbOpenDynaset, dbSeeChanges)
Call SaveAsOfficePDF(rs![Learner ID])
rs1.Close
Set rs1 = Nothing
rs.MoveNext
Loop
end sub
Private Sub cmdCreateEmails_Click()
'this is the other half of the biggie, sewing it all together
Dim db As Database
Dim rs As Recordset
Dim rs1 As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("select distinct [learner id] from qryDelinquencies", dbOpenDynaset, dbSeeChanges)
rs.MoveLast
rs.MoveFirst
Do Until rs.EOF = True
Set rs1 = db.OpenRecordset("Select * from qryLearnerDetails where [Learner ID] = " & Chr(34) & rs![Learner ID] & Chr(34), dbOpenDynaset, dbSeeChanges)
Call CreateAnEmail(rs![Learner ID] & ".pdf", rs1!FullName, Nz(rs1!Email, ""), Nz(rs1![Supervisor Email], ""))
rs1.Close
Set rs1 = Nothing
rs.MoveNext
Loop
EnoughPrompts = 0
End Sub
Me.txtBlurb.Value = [First] & " " & [Last] & ", you are receiving this Notice to File for failure to complete your required compliance training by the due date. You were required to complete:" & vbCrLf & vbCrLf
Private Sub cmdCreatePdfs_Click()
'this is the half the biggie, sewing it all together
Dim db As Database
Dim rs As Recordset
Dim rs1 As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("select distinct [learner id] from qryDelinquencies", dbOpenDynaset, dbSeeChanges)
rs.MoveLast
rs.MoveFirst
Do Until rs.EOF = True
Set rs1 = db.OpenRecordset("Select * from qryLearnerDetails where [Learner ID] = " & Chr(34) & rs![Learner ID] & Chr(34), dbOpenDynaset, dbSeeChanges)
Call SaveAsOfficePDF(rs![Learner ID])
rs1.Close
Set rs1 = Nothing
rs.MoveNext
Loop
End Sub
Private Sub cmCreatePDFs_Click()
'half
Dim db As Database
Dim rs As Recordset
Dim rs1 As Recordset
Dim rsRegions As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("select distinct [learner id] from qryDelinquencies", dbOpenDynaset, dbSeeChanges)
Set rsRegions = db.OpenRecordset("select distinct [BA] from qryDelinquencies", dbOpenDynaset, dbSeeChanges) 'recordset with the possible regions
rs.MoveLast
rs.MoveFirst
rsRegions.MoveLast
rsRegions.MoveFirst
Do Until rsRegions.EOF = True 'loop through regions
Do Until rs.EOF = True 'loop through each learner in the region
Set rs1 = db.OpenRecordset("Select * from qryLearnerDetails where [Learner ID] = " & Chr(34) & rs![Learner ID] & Chr(34) & " and [BA] = " & Chr(34) & rsRegions![BA] & Chr(34), dbOpenDynaset, dbSeeChanges)
Call SaveAsOfficePDF(rs![Learner ID], DLookup("RegionPath", "tblRegionPaths", "[BA] = " & Chr(34) & rsRegions![BA] & Chr(34)))
'SaveAsOfficePDF now takes the learnerID for the file name and a full path to store the file in
'path needs a trailing \ ie c:\tempPDF\
'I presumed you'd create a table
'if not, you need to code another method to pass in that path
rs1.Close
Set rs1 = Nothing
rs.MoveNext
Loop
rsRegions.MoveNext
Loop
End Sub
Private Sub SaveAsOfficePDF(LearnerID As String, RegionPath As String)
Dim FormatValue As String
If Application.Version > 11 Then
FormatValue = "PDF Format (*.pdf)"
Else
FormatValue = acFormatRTF
End If
Dim stdocname As String
stdocname = "rptLearnerDelinquencyNotice"
DoCmd.OpenReport stdocname, acPreview, , "[Learner ID] = " & Chr(34) & LearnerID & Chr(34)
DoCmd.OutputTo acOutputReport, stdocname, FormatValue, RegionPath & LearnerID & ".pdf"
DoCmd.Close acReport, stdocname, acSaveYes
End Sub
Person 1, Course 1
Person 1, Course 2
person 1, Course 3
or
Person 1, Course 1, Course 2, Course 3 (All in one record?)