Template Select

samuelbrr

New member
Local time
Today, 17:50
Joined
Apr 20, 2005
Messages
5
Hello,

Basically I am using access to populate a pre-made word template but I was wondering if its possible to be able to insert a dropdown box where I can select the template I need to use.

I use the following VB code:

Code:
Private Sub Command40_Click()
'Written by Helen Feddema 4-22-98
'Last modified 8-2-2000

On Error GoTo ErrorHandler

   Dim appWord As Word.Application
   Dim docs As Word.Documents
   Dim strLetter As String
   Dim strTemplateDir As String
   Dim prps As Object
   Dim strDate As String
   
   Set appWord = GetObject(, "Word.Application")
   strDate = CStr(Date)
   
   Debug.Print "Office templates directory: " & strTemplateDir
   strLetter = "\\Mainpc\shareddocs\BACKUP\CallTechSupport\database\print_forms\work_order.dot"
   Debug.Print "Letter: " & strLetter
   
   Set docs = appWord.Documents
   docs.Add strLetter
   
   Set prps = appWord.ActiveDocument.CustomDocumentProperties
   
   With prps
      .Item("TodayDate").Value = strDate
      .Item("Name").Value = Nz(Me![txtName])
      .Item("Address1").Value = Nz(Me![txtBillingAddress])
      .Item("City").Value = Nz(Me![txtCity])
      .Item("Region").Value = Nz(Me![txtRegion])
      .Item("PostCode").Value = Nz(Me![txtPostCode])
      .Item("Phone").Value = Nz(Me![txtPhone])
      .Item("WorkID").Value = Nz(Me![WorkorderID])
      .Item("DateReceived").Value = Nz(Me![DateReceived])
      .Item("DateRequired").Value = Nz(Me![DateRequired])
      .Item("CustomerID").Value = Nz(Me![CustomerID])
      .Item("AssignedTo").Value = Nz(Me![EmployeeID])
      .Item("MakeAndModel").Value = Nz(Me![MakeAndModel])
      .Item("SerialNo").Value = Nz(Me![SerialNumber])
      .Item("ProblemDescription").Value = Nz(Me![ProblemDescription])
      .Item("WorkDone").Value = Nz(Me![txtWorkDone])
      .Item("email").Value = Nz(Me![txtEmailAddress])
   End With
   
   With appWord
      .Visible = True
      .Activate
      .Selection.WholeStory
      .Selection.Fields.Update
      .Selection.MoveDown Unit:=wdLine, Count:=1
   End With

ErrorHandlerExit:
   Exit Sub

ErrorHandler:
   If Err = 429 Then
      'Word is not running; open Word with CreateObject
      Set appWord = CreateObject("Word.Application")
      Resume Next
   Else
      MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
      Resume ErrorHandlerExit
   End If

    
End Sub
 

Users who are viewing this thread

Back
Top Bottom