Notices

Great community. Great ideas.

Welcome to ASP/Free, a community dedicated to helping beginners and professionals alike in improving their knowledge of Microsoft's development and administration technologies. Sign up today to gain access to the combined insight of tens of thousands of members.

Thread: Export word file to folder from Access form

Results 1 to 7 of 7
Share This Thread →
  1. #1
    JPR
    JPR is offline Contributing User
    Join Date
    Sep 2005
    Posts
    379
    Rep Power
    9

    Export word file to folder from Access form

    Hello friends,
    Perhaps I am pushing my luck to far but some time ago I did ask this question and did not found a solution. Since you have been great until now, I am submittin a sample zip file of my db so that you can better understand what is my project.
    Data from my access forms are normally exported to word templates. Once I click on a cmdbutton, the data is exported using bookmarks and opens the word file. Users then can choose if to save it and where to save it.
    I would like to avoid this step. I would like to place a second cmd button which directly exports data the word file and saves it into a specific folder (let's say it could be C:\myforms\myname

    Can anyone help with this? I believe the procedure will need some input box so that users can assign the name to the file (as they are templates) before saving it. Thanks.
    Attached Files Attached Files

  2. #2
    Fowler_ko is offline Contributing User
    Join Date
    Apr 2004
    Location
    Cumbria, UK
    Posts
    435
    Rep Power
    112
    You are on the right tracks with what you already have... If you copy the same code you already use to open word file and export the data, then change the line the shows word (objword.visible = true) to the following:

    Code:
    objWord.ActiveDocument.SaveAs "C:\users\jbloggs\desktop\test.docĒ
    objWord.Quit
    This will save the document to the location in the string, in this case joes desktop, this string can be easily changed to pick up a save location and filename from a table, form control or inputbox.

    Let us know how you come on...

  3. #3
    JPR
    JPR is offline Contributing User
    Join Date
    Sep 2005
    Posts
    379
    Rep Power
    9
    Thank you very much. It was a long time I was looking for this and finally got it. Your code works fine but I have changed a small part so fit my needs. It now assigns the name to the word file based on the SSN field which is a unique records. My last question is if it is possible to change the path to a string so that users will not need to open the db and change the path into which export the docs. THey can simply open a table via mask.
    I would like to save the path into which save these word docs into a table (table is called Templates Path the Field is named Template Location) .
    Thank you.

    On Error Resume Next
    Dim objWord As Object
    Dim strPath As String


    strPath = DLookup("[TemplateLocation]", "TablePath", "[TemplateID]='" & Me.[TXTPATH] & "'")

    Set objWord = CreateObject("Word.Application")
    objWord.Visible = False

    objWord.Documents.Add strPath


    '---
    objWord.ActiveDocument.Bookmarks("SSN").Select
    objWord.Selection.Text = Left([SSN], 3) & "-" & Mid([SSN], 4, 2) & "-" & Right([SSN], 4)

    objWord.ActiveDocument.SaveAs "C:\Users\E\Desktop\" & Me![SSN] & ".doc"
    objWord.Quit
    MsgBox ("your form has been saved in Word format")

  4. #4
    Fowler_ko is offline Contributing User
    Join Date
    Apr 2004
    Location
    Cumbria, UK
    Posts
    435
    Rep Power
    112
    I would use similar code to what you use to get the template name, you could store this in the same table...

    Code:
    strSavePath = DLookup("[TemplateLocation]", "TablePath", "[TemplateID]='WordSavePath'")
    objWord.ActiveDocument.SaveAs strSavePath & Me![SSN] & ".doc"
    You would have to add a line in the table that contains the save path and enter 'WordSavePath' into the TempleteId field. If you want to save it in a different table then you should be able to change the table name and field names in the dlookup line...

  5. #5
    JPR
    JPR is offline Contributing User
    Join Date
    Sep 2005
    Posts
    379
    Rep Power
    9
    Thanks, just great! Just to finish my work, is there a way I can export directly to a specific folder as indicated in a textbox on my form?
    Example.
    In my db all users have an initials. These are stored in a table named INITIALS which has a field also named INITIALS.
    Let' say, that my initials are AAA. When I open a form, I have a txtbox named txtinitials, which will show my initials.
    The same way on my server drive I have different folders each one named according to the users initials. THe word doc should be saved directly into the folder named AAA.

    This is where I am having problems. Appreciate your extra help.
    Last edited by JPR; September 21st, 2009 at 06:24 AM. Reason: New Question

  6. #6
    JPR
    JPR is offline Contributing User
    Join Date
    Sep 2005
    Posts
    379
    Rep Power
    9
    Sorry but resubmitting my question as erroneously written in the edit mode.

    Just to finish my work, is there a way I can export directly to a specific folder as indicated in a textbox on my form?
    Example.
    In my db all users have an initials. These are stored in a table named INITIALS which has a field also named INITIALS.
    Let' say, that my initials are AAA. When I open a form, I have a txtbox named txtinitials, which will show my initials.
    The same way on my server drive I have different folders each one named according to the users initials. THe word doc should be saved directly into the folder named AAA.

    This is where I am having problems. Appreciate your help.

  7. #7
    Fowler_ko is offline Contributing User
    Join Date
    Apr 2004
    Location
    Cumbria, UK
    Posts
    435
    Rep Power
    112
    You should be able to build up the path in the same way you added the SSN no to the filename...

    Code:
    strSavePath = DLookup("[TemplateLocation]", "TablePath", "[TemplateID]='WordSavePath'")
    objWord.ActiveDocument.SaveAs strSavePath & Me![txtinitials] & "\" & Me![SSN] & ".doc"

Share This Thread →

Become Part of This Conversation

Join NowFor Free!

Similar Threads

  1. Export to MS Word bookmarks
    By JPR in forum Microsoft Access Help
    Replies: 1
    Last Post: March 7th, 2006, 03:00 PM
  2. Export Access to Excel help Please!
    By sdd872 in forum Microsoft Access Help
    Replies: 2
    Last Post: December 16th, 2005, 09:06 AM
  3. Replies: 3
    Last Post: September 22nd, 2005, 10:23 AM
  4. opening word document with info from Access form
    By blloyd in forum Microsoft Access Help
    Replies: 3
    Last Post: February 15th, 2005, 02:53 PM
  5. Web serverístatistical analysis
    By cso in forum ASP Development
    Replies: 0
    Last Post: April 19th, 2003, 11:35 AM

ASP Free Advertisers and Affiliates