Option Compare Database
Global Const ClientTemplate = "CL1.DOT"
Global ClientAccLet As String
Global WhoRu As Variant 'Client ID
Global ThisJob As Variant 'Job ID
Global ThisXS As Variant 'XS_Job_ID
Global ThisList As Variant 'XS_List_ID
Dim objWord As Word.Application
Dim docWord As Word.Document
Public Function Letter2Client()
Dim AA As Variant
Dim BB As Variant
Dim CC As Variant
Dim DD As Variant
Dim temp As Variant
'Establish details
Est_Det
'Create the letter
name_stuff
Set objWord = New Word.Application
Set docWord = objWord.Documents.Add(ClientAccLet)
'Make the application visible.
objWord.Visible = True
'FRANCHISE PHONE NUMBER
temp = DLookup("[Franchise ID]", "[Job]", "[Job ID] = " & ThisJob) 'ORDER IS VITAL 1
AA = DLookup("phone", "[Franchise]", "[franchise ID] = " & temp)
temp = Word_Inst(AA, "F_tel_no", ClientAccLet) 'ORDER IS VITAL 2
'FRANCHISE EMAIL
temp = DLookup("[Franchise ID]", "[Job]", "[Job ID] = " & ThisJob) 'ORDER IS VITAL 4
AA = DLookup("eMail", "[Franchise]", "[franchise ID] = " & temp)
temp = Word_Inst(AA, "F_e_mail", ClientAccLet) 'ORDER IS VITAL 5
'Others maybe done with the search replace system
'Header
'List items for each feature in Job
'Terms and conditions
'List + Price of each feature
'Footer
'Search and replace {TAGS}
'Give Result succeed/fail
End Function
Private Sub Est_Det()
'Double check the given values and fill in the blanks
'Calculate the Job from the XS_Job
ThisJob = DLookup("[Job ID]", "[XS_JOB_link]", "[Job_Link_ID] = " & ThisXS)
'Get the attached Client ID
WhoRu = DLookup("[customer id]", "[Job]", "[Job ID] = " & ThisJob)
End Sub
Private Function Word_Inst(Source, Target_BM, Target_Doc As Variant)
Dim tApp As Object
Dim Selected_Word_Text As Variant
Set tApp = GetObject(WhereAmI & "\" & Target_Doc, "Word.Document")
'tApp.Visible = True
If tApp.Bookmarks.Exists(Target_BM) = True Then
tApp.Bookmarks(Target_BM).Select
objWord.Selection.Text = Source
Else
MsgBox "DEBUGGING: """ & Target_BM & """ does not exist error in Word_Inst."
End If
End Function
Private Sub name_stuff()
'Name the new open doc (from template)
ClientAccLet = "ClientLetter" & Day(Now) & "_" & Month(Now) & "_" & Year(Now) & " " & Hour(Now) & Minute(Now) & "hrs" & ".Doc"
MsgBox ClientAccLet
FileCopy WhereAmI & "\" & ClientTemplate, WhereAmI & "\" & ClientAccLet
End Sub