asked on
Sub logInNotes(this_form As Form, mode As String, CTYPE As String)
' stick log entry and/or template in Word notes
'
' "L" log only
' "T" template only
' "LT" both
Dim blret As Boolean, RTFstring As String
Dim docapp As Object
Dim docdoc As Object
Dim password As String, thislog As String
Dim junk As Integer
Dim temppath As String
' paragraph and range objects for bookmark/borders code
Dim rng As Object
Dim par As Object
' open up the file
On Error GoTo logInNotes_Error
15 Set docapp = CreateObject("Word.Application")
'40 On Error GoTo notFound
50 password = DLookup("[password readwrite]", "[my details]")
60 Set docdoc = docapp.Documents.Open("C:\program files\COUNSELOG 4.2\cg4 docs\" & _
Forms!switchboard!thisuser & "\" & Forms![counselling log].client_on_form & ".docx", _
, , , password, , , password)
'70 On Error GoTo logInNotes_Error
' timestamp always if we got this far...
90 docapp.Selection.EndKey Unit:=wdStory ' to the end of text
100 docapp.Selection.Font.size = 11
110 docapp.Selection.TypeText vbCrLf & "___________________________" & vbCrLf ' timestamp
120 docapp.Selection.TypeText CTYPE & " session on " & _
Format(Forms![counselling log]!date_on_form, "MMMM dd, yyyy") & _
", session number " & Forms![counselling log]!sesno & vbCrLf
' stick in log entry?
130 If InStr(mode, "L") Then
140 docapp.Selection.Font.size = 13
150 docapp.Selection.TypeText "Log for session: " & vbCrLf
' plant starting bookmark
160 docdoc.Bookmarks.Add "start", docapp.Selection.Range
' plant text from Access field
171 thislog = Forms![counselling log].[dealt with] ' convert to string from access field
172 docapp.Selection.TypeText RegExpReplace(thislog, "<(.|\n)*?>") & vbCrLf & vbCrLf
' make a range from bookmark to where we are now
'Set rng = docdoc.Range(docdoc.Bookmarks("start").Range.end, docapp.Selection.end)
210 Set rng = docdoc.Range(docdoc.Bookmarks("start").end, docapp.Selection.end) ' create range to cover all text imported
' enable borders for all paras in this range
220 For Each par In rng.Paragraphs
230 par.Borders.Enable = True
240 Next par
250 End If
' stick in template?
260 If InStr(mode, "T") Then
270 temppath = DLookup("[session template path]", "[my details]")
280 If IsNull(temppath) Then
290 Call tellIt(Forms![session log]!Label193, Forms![session log], False)
300 Else
310 docapp.Selection.insertfile temppath
320 End If
330 End If
360 Set rng = Nothing
370 Set par = Nothing
340 docdoc.Close wdSaveChanges
350 docapp.Quit
380 Set docdoc = Nothing
390 Set docapp = Nothing
'go home
On Error GoTo 0
Exit Sub
notFound:
450 Call tellIt(this_form.Label162, this_form, False)
460 Exit Sub
logInNotes_Error:
MsgBox "Error " & err.number & _
" (" & err.description & _
") from >" & err.source & _
"< in line " & Erl & _
" in procedure 'logInNotes' of Module 'global'", vbExclamation
End Sub