Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Join Date
    Mar 2007
    Posts
    91

    Unanswered: Inserting data into word document

    Hi guys

    Is it possible to insert data into a word document. ie whenever a user takes a certain action - data should be added into the word document (which will b in a shared folder)

    If so can u pls kindly assist

    Noks

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    The simpler solution would be a text file (*.txt)
    Code:
    Private Sub Command0_Click()
    Dim strLine As String
    
        'Create the new writeout file
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set a = fs.CreateTextFile("C:\testfile.txt", True)
    
        strLine = Environ("Username") & " just clicked Command0"
            'Write amended line to the textfile
            a.writeline strLine
            'close the object
            a.Close
    End Sub
    George
    Home | Blog

  3. #3
    Join Date
    Mar 2007
    Posts
    91
    Thank u. This was really helpful

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You may want to make a note of what happens when you click the button a number of times. Do it then open the file - see what I mean?
    The above code is only part of your solution
    George
    Home | Blog

  5. #5
    Join Date
    Mar 2007
    Posts
    91
    I have opted for creating the document prior, then using a bookmark. I have never done this before but i hope and actually have faith that it will work

    Thanks

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Just had a quick thought - if this is an audit log style file then this is the wrong approach.
    If this file is in a shared folder and is far too vunerable to modification / deletion.
    If you wish to keep this method then you may want to implement a "if the file does not exist then create it" within your write to file function
    George
    Home | Blog

  7. #7
    Join Date
    Mar 2007
    Posts
    91
    Sample am using as reference for my doc http://www.access-programmers.co.uk/...d.php?t=109497 and here's my code

    CODE:
    'When enabled disable Happy_with_our_service
    If Not Me.Service_No.Value = -1 Then
    Happy_with_our_service_.Enabled = True
    Else
    Happy_with_our_service_.Enabled = False
    ' Sending a mail to the Assistant of the manager if the customer's not happy with our service
    'Save the person's name to the shared
    'Declare the follwing

    'Declare the follwing
    Dim objWord As Word.Application

    'Set word as an application and make it invisible
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = False 'True is visible

    'path and name of the template your are using.
    objWord.Documents.Add ("M:JMC\Operations\Projects\Molo\Unhappy_Customers .doc")

    'This is for the bookmark that you created in the template
    objWord.ActiveDocument.Bookmarks("Unhappy_C").Sele ct - error msg = Run-time error '4248':
    This command is not vailable because no document is open


    'This is the field in access that containts the data that has to be entered at the
    'bookmark
    objWord.Selection.Text = Forms![molo]![Unique_ID]


    'Word (or the document that you created with the template, will now open)
    objWord.Visible = True


    Set objWord = Nothing


    End If


    End Sub


    Pls kindly help

    Noks
    Last edited by noks; 06-04-07 at 09:23.

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I've never come across bookmarks before but does the error stem from the extra spaces in
    Code:
    objWord.Documents.Add ("M:JMC\Operations\Projects\Molo\Unhappy_Customers .doc")
    
    'This is for the bookmark that you created in the template
    objWord.ActiveDocument.Bookmarks("Unhappy_C").Sele ct
    Please wrap your code in code tags in the future
    George
    Home | Blog

  9. #9
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    I don't know why it should fail there with that error message. You sure it is not the line before because that path looks dodgy? BTW - I would always make everything visible while debugging - you can see a lot then. Hide it if you must when live.

    If everything is as you say then what happens if you try:

    Code:
    ....
     
    'path and name of the template your are using.
    objWord.Documents.Add ("M:JMC\Operations\Projects\Molo\Unhappy_Customers .doc")
     
    Dim oDoc As Word.Document
    Set oDoc = objWord.Documents(1)
     
    'This is for the bookmark that you created in the template
    oDoc.Bookmarks("Unhappy_C").Select 
    ....
    Testimonial:
    pootle flump
    ur codings are working excelent.

  10. #10
    Join Date
    Mar 2007
    Posts
    91
    Quote Originally Posted by pootle flump
    Code:
    ....
     
    Set oDoc = objWord.Documents(1)
     
    ....
    Error msg = the requested member of the collection does not exist

    Quote Originally Posted by pootle flump
    Code:
    ....
     
    Set oDoc = objWord.Documents
     
    ....
    Error msg = Run-time error 13 (type mismatch)


  11. #11
    Join Date
    Mar 2007
    Posts
    91
    Quote Originally Posted by georgev
    I've never come across bookmarks before but does the error stem from the extra spaces in
    Code:
    objWord.Documents.Add ("M:JMC\Operations\Projects\Molo\Unhappy_Customers .doc")
    
    'This is for the bookmark that you created in the template
    objWord.ActiveDocument.Bookmarks("Unhappy_C").Sele ct
    Please wrap your code in code tags in the future
    in my code everything (Words) r combined correctly. I have no idea y when i copy the code here, it should come out like that. I've tried editing the code but unfortunately that also didn't help

  12. #12
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Try
    Code:
    Set oDoc = objWord.Documents(0)
    Arrays start from zero
    The second line failed because .Documents is a collection and you have not specified which item in the collection you want to access (like above).
    George
    Home | Blog

  13. #13
    Join Date
    Mar 2007
    Posts
    91
    Quote Originally Posted by georgev
    Try
    Code:
    Set oDoc = objWord.Documents(0)
    Arrays start from zero
    The second line failed because .Documents is a collection and you have not specified which item in the collection you want to access (like above).
    It still doesn't make any difference. I still get the same error message

    Thanks

  14. #14
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Why exactly are we using bookmarks?
    George
    Home | Blog

  15. #15
    Join Date
    Mar 2007
    Posts
    91
    Quote Originally Posted by georgev
    Why exactly are we using bookmarks?
    When i did a search on inserting data into word document using ms access i came across using bookmarks or merge to word. So i figured since i was gonna be writing the same info bout different customers i should use bookmarks coz i can write the "static info" then just edit where needed to.

    I haven't used them both before but i figured bookmarks will be less complicated than the other option.

Posting Permissions

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