I have a module of code (Given below) that is supposed to find sections in a word document and then change them based on values it gets from the database and other word documents. In theory it works perfectly (to my mind) but in practice I get an error:
Object variable or With block variable not set
And this line is marked:
now when ever I try to put SOMETHING_LIKELY.objWord... I get not possable, not supported, error - what do you think you are doing bo-zo... etc. All I need to do is select the section of text covered by the bookmark and replace with my own.VB Code:
objWord.Selection.Text = Source
I know that:
Will actually pass the text out but passing it in seems to be problematical. Any help on getting this sequence finnished before the boss and the client murder me would be niceVB Code:
'Where Start_BM is a variable for nameing bookmarks Selected_Word_Text = sApp.Bookmarks(Start_BM).Range.Text
This is the code in context:
VB Code:
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 'FRANCHISE PHONE NUMBER temp = DLookup("[Franchise ID]", "[Job]", "[Job ID] = " & ThisJob) AA = DLookup("phone", "[Franchise]", "[franchise ID] = " & temp) temp = Word_Inst(AA, "F_tel_no", ClientAccLet) 'FRANCHISE EMAIL temp = DLookup("[Franchise ID]", "[Job]", "[Job ID] = " & ThisJob) AA = DLookup("eMail", "[Franchise]", "[franchise ID] = " & temp) temp = Word_Inst(AA, "F_e_mail", ClientAccLet) Set objWord = CreateObject("Word.Application") Set docWord = objWord.Documents.add(ClientAccLet) 'Make the application visible. objWord.Visible = True End Function Private Sub Est_Det() 'Get's variables based on the globals to ensure all are filled 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() 'Assigns "names" into the variables etc End Sub
Thanx





Reply With Quote