Re: Word Template Automation
From: Eric Lawrence [MSFT] (e_lawrence_at_hotmail.com)
Date: 02/22/04
- Previous message: Frank Brady: "Word Template Automation"
- In reply to: Frank Brady: "Word Template Automation"
- Next in thread: anonymous_at_discussions.microsoft.com: "Re: Word Template Automation"
- Reply: anonymous_at_discussions.microsoft.com: "Re: Word Template Automation"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 21 Feb 2004 17:46:42 -0800
Is there some reason your template filename doesn't have a file extension?
--
Thanks,
Eric Lawrence
Program Manager
Assistance and Worldwide Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"Frank Brady" <anonymous@discussions.microsoft.com> wrote in message
news:1436b01c3f8c7$17576650$a001280a@phx.gbl...
> The following code opens a word template as a new document
> and appends text to the new document. This works in
> Windows 98, however when ported to Windows XP I get ERROR
> 5152 - this is not a valid file name. The file is there
> and it is not corrrupt.
>
> The error occurs in the following line:
>
> Set doc1 = wrd.Documents.Add
> (Template:="c:\Access\Data\RefLetterTemp",
> NewTemplate:=False)
>
>
>
> Private Sub cmdReferralLetter_Click()
> Dim db As Database
> Dim rs As Recordset
> Dim strSql As String
> Dim strMD
>
> On Error GoTo err_handler
>
> strSql = "SELECT * FROM tblPhysican where
> tblPhysican.ID = """ & strMD & """;"
> Set db = CurrentDb
> Set rs = db.OpenRecordset(strSql)
>
> Dim wrd As Word.Application
> Dim doc1 As Word.Document
> Dim rng As Word.Range
> Dim SerNo As String
> SerNo = CStr(CDec(Time()))
> SerNo = Mid(SerNo, InStr(SerNo, ".") + 1)
>
> Set wrd = New Word.Application
>
> 'set pointer to new doc based on Referral templet
> Set doc1 = wrd.Documents.Add
> (Template:="c:\Access\Data\RefLetterTemp",
> NewTemplate:=False)
>
> With wrd.ActiveDocument
> Set rng = .Bookmarks("DrName").Range
> rng.InsertBefore Nz(rs!FNAME & " " & rs!LNAME & "
> M.D.")
> Set rng = .Bookmarks("DrStreet").Range
> rng.InsertBefore Nz(rs!ADDR1)
>
> If rs!ADDR2 <> "" Then
> Set rng = .Bookmarks("DrAddLn2").Range
> rng.InsertBefore vbCrLf & Nz(rs!ADDR2)
> End If
>
> Set rng = .Bookmarks("DrCSZ").Range
> rng.InsertBefore Nz(rs!City) & ", " & Nz(rs!State)
> & " " & Nz(rs!Zip) & vbCrLf & vbCrLf
> Set rng = .Bookmarks("DrLname").Range
> rng.InsertBefore Nz(rs!LNAME)
> Set rng = .Bookmarks("Re").Range
> rng.InsertBefore Forms![frmpatients]![LNAME] & ", "
> & Forms![frmpatients]![FNAME]
> Set rng = .Bookmarks("PtFname").Range
> rng.InsertBefore Forms![frmpatients]![FNAME]
> Set rng = .Bookmarks("HeShe").Range
> rng.InsertBefore IIf(Forms![frmpatients]![SEX]
> = "M", "He", "She")
> Set rng = .Bookmarks("DOS").Range
> rng.InsertBefore Format(Me![DateSeen], "dddd, mmm d
> yyyy")
> ' Returns "Wednesday, Jan 27 1993".
> Set rng = .Bookmarks("Note").Range
> rng.InsertBefore Nz(Me![Note])
>
> .SaveAs "C:\My Documents\" & rs!LNAME & SerNo
> End With
>
> wrd.Visible = True
>
>
> exit_Hear:
> Set rng = Nothing
> Set doc1 = Nothing
> Set wrd = Nothing
> Exit Sub
>
> err_handler:
> Select Case Err.Number
> Case Else
> MsgBox Err.Number & " " & Err.Description,
> vbExclamation, "Error Referal Letter to MS Word"
> End Select
> Resume exit_Hear
>
> End Sub
- Previous message: Frank Brady: "Word Template Automation"
- In reply to: Frank Brady: "Word Template Automation"
- Next in thread: anonymous_at_discussions.microsoft.com: "Re: Word Template Automation"
- Reply: anonymous_at_discussions.microsoft.com: "Re: Word Template Automation"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|