Results 1 to 15 of 15

Thread: Dealing with word from access ***RESOLVED***

Threaded View

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Dealing with word from access ***RESOLVED***

    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:

    VB Code:
    1. objWord.Selection.Text = Source
    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.

    I know that:

    VB Code:
    1. 'Where Start_BM is a variable for nameing bookmarks
    2.         Selected_Word_Text = sApp.Bookmarks(Start_BM).Range.Text
    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 nice

    This is the code in context:
    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. Public Function Letter2Client()
    15. Dim AA As Variant
    16. Dim BB As Variant
    17. Dim CC As Variant
    18. Dim DD As Variant
    19. Dim temp As Variant
    20.  
    21.     'Establish details
    22.     Est_Det
    23.     'Create the letter
    24.     name_stuff
    25.    
    26.    
    27.     'FRANCHISE PHONE NUMBER
    28.     temp = DLookup("[Franchise ID]", "[Job]", "[Job ID] = " & ThisJob)  
    29.     AA = DLookup("phone", "[Franchise]", "[franchise ID] = " & temp)
    30.     temp = Word_Inst(AA, "F_tel_no", ClientAccLet)                      
    31.    
    32.     'FRANCHISE EMAIL
    33.     temp = DLookup("[Franchise ID]", "[Job]", "[Job ID] = " & ThisJob)  
    34.     AA = DLookup("eMail", "[Franchise]", "[franchise ID] = " & temp)
    35.     temp = Word_Inst(AA, "F_e_mail", ClientAccLet)                      
    36.    
    37.     Set objWord = CreateObject("Word.Application")
    38.     Set docWord = objWord.Documents.add(ClientAccLet)
    39.     'Make the application visible.
    40.     objWord.Visible = True
    41.    
    42. End Function
    43.  
    44.  
    45. Private Sub Est_Det()
    46. 'Get's variables based on the globals to ensure all are filled
    47. End Sub
    48.  
    49.  
    50. Private Function Word_Inst(Source, Target_BM, Target_Doc As Variant)
    51. Dim tApp As Object
    52. Dim Selected_Word_Text As Variant
    53.  
    54.     Set tApp = GetObject(WhereAmI & "\" & Target_Doc, "Word.Document")
    55.     'tApp.Visible = True
    56.     If tApp.Bookmarks.Exists(Target_BM) = True Then
    57.         tApp.Bookmarks(Target_BM).Select
    58.         objWord.Selection.Text = Source
    59.     Else
    60.         MsgBox "DEBUGGING: """ & Target_BM & """ does not exist error in Word_Inst."
    61.     End If
    62.    
    63. End Function
    64.  
    65. Private Sub name_stuff()
    66. 'Assigns "names" into the variables etc
    67. End Sub



    Thanx
    Last edited by Matt_T_hat; Aug 5th, 2003 at 10:26 AM.
    ?
    'What's this bit for anyway?
    For Jono

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width