It does no like

VB Code:
  1. Set docWord = objWord.Documents.Add(ClientAccLet)

it now gives error 5151

when I mouse over the variable names to get values I see this

ClientAccLet = “ClientLetter5_8_2003 1323hrs.Doc”
Word.Application = <Object variable or With block variable not set>
ObjWord.Visible = <The remote server machine does not exist or is unavailable>


Last time I trimed down the VB code but this time I'm going to post it all. This means that this is going to be a long post (sorry).

WhereAmI is a fuction that returns the current application path

Job and XS_Job are different tables (I'm not messing around with funny set-ups)

VB Code:
  1. Option Compare Database
  2.  
  3. Global Const ClientTemplate = "CL1.DOT"
  4. Global ClientAccLet As String
  5.  
  6. Global WhoRu As Variant 'Client ID
  7. Global ThisJob As Variant 'Job ID
  8. Global ThisXS As Variant 'XS_Job_ID
  9. Global ThisList As Variant 'XS_List_ID
  10. Dim objWord As Word.Application
  11. Dim docWord As Word.Document
  12.  
  13.  
  14.  
  15. Public Function Letter2Client()
  16. Dim AA As Variant
  17. Dim BB As Variant
  18. Dim CC As Variant
  19. Dim DD As Variant
  20. Dim temp As Variant
  21.  
  22.     'Establish details
  23.     Est_Det
  24.     'Create the letter
  25.     name_stuff
  26.    
  27.     Set objWord = New Word.Application
  28.     Set docWord = objWord.Documents.Add(ClientAccLet)
  29.    
  30.     'Make the application visible.
  31.     objWord.Visible = True
  32.    
  33.     'FRANCHISE PHONE NUMBER
  34.     temp = DLookup("[Franchise ID]", "[Job]", "[Job ID] = " & ThisJob)  'ORDER IS VITAL   1
  35.     AA = DLookup("phone", "[Franchise]", "[franchise ID] = " & temp)
  36.     temp = Word_Inst(AA, "F_tel_no", ClientAccLet)                      'ORDER IS VITAL  2
  37.    
  38.     'FRANCHISE EMAIL
  39.     temp = DLookup("[Franchise ID]", "[Job]", "[Job ID] = " & ThisJob)  'ORDER IS VITAL   4
  40.     AA = DLookup("eMail", "[Franchise]", "[franchise ID] = " & temp)
  41.     temp = Word_Inst(AA, "F_e_mail", ClientAccLet)                      'ORDER IS VITAL  5
  42.    
  43.     'Others maybe done with the search replace system
  44.    
  45.     'Header
  46.     'List items for each feature in Job
  47.     'Terms and conditions
  48.     'List + Price of each feature
  49.     'Footer
  50.     'Search and replace {TAGS}
  51.     'Give Result succeed/fail
  52. End Function
  53.  
  54. Private Sub Est_Det()
  55.   'Double check the given values and fill in the blanks
  56.  
  57.   'Calculate the Job from the XS_Job
  58.   ThisJob = DLookup("[Job ID]", "[XS_JOB_link]", "[Job_Link_ID] = " & ThisXS)
  59.   'Get the attached Client ID
  60.   WhoRu = DLookup("[customer id]", "[Job]", "[Job ID] = " & ThisJob)
  61. End Sub
  62.  
  63.  
  64. Private Function Word_Inst(Source, Target_BM, Target_Doc As Variant)
  65. Dim tApp As Object
  66. Dim Selected_Word_Text As Variant
  67.  
  68.     Set tApp = GetObject(WhereAmI & "\" & Target_Doc, "Word.Document")
  69.     'tApp.Visible = True
  70.     If tApp.Bookmarks.Exists(Target_BM) = True Then
  71.         tApp.Bookmarks(Target_BM).Select
  72.         objWord.Selection.Text = Source
  73.     Else
  74.         MsgBox "DEBUGGING: """ & Target_BM & """ does not exist error in Word_Inst."
  75.     End If
  76.    
  77. End Function
  78.  
  79. Private Sub name_stuff()
  80. 'Name the new open doc (from template)
  81.     ClientAccLet = "ClientLetter" & Day(Now) & "_" & Month(Now) & "_" & Year(Now) & " " & Hour(Now) & Minute(Now) & "hrs" & ".Doc"
  82.     MsgBox ClientAccLet
  83.     FileCopy WhereAmI & "\" & ClientTemplate, WhereAmI & "\" & ClientAccLet
  84. End Sub