Page 1 of 3 123 LastLast
Results 1 to 15 of 40
  1. #1
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167

    Export to Word Table

    Dear friends,




    I would like to have your help in the following:


    I have a continuous form which i can create a weekly meal plan. Through the form I can select the day, the type of meal and then the portion size.


    I want to export these data into a Word file and especially into a Word Table depending on the type of meal. Is that possible?

    I attach an example of the database as well as the Word file


    Thanks in advanced
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    It's possible but because it is not a straightforward mailmerge (need to populate a Word table), code gets a little complicated. Review https://www.accessforums.net/access/...rds-20712.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Hi June7,

    I tried with the following code but i'm getting errors...i'm not so familar with vba.. Can you help me please to build the code?

    Private Sub cmdWord_Click()
    'Γέμισμα πίνακα του Word


    Dim appWord As Object, D As String, K As String
    Dim Col As Integer, Row As Integer, DocName As String
    Dim doc As Object, j As Long



    DocName = "DietPlan.dot"


    If Me.RecordsetClone.RecordCount Then

    On Error Resume Next
    Err.Clear


    Set appWord = GetObject(, "Word.Application")


    If Err.Number <> 0 Then


    Set appWord = CreateObject("Word.Application")


    End If


    On Error GoTo errHandler


    appWord.Documents.Add CurrentProject.Path & "\" & DocName
    Set doc = appWord.Documents(appWord.Documents.Count)


    With Me.RecordsetClone
    .MoveFirst
    Do Until .EOF
    For j = 1 To .Fields.Count - 2
    D = .Fields(j).Name
    K = !MealCode
    Row = Switch(K = "Breakfast", 2, K = "Snak1", 3, K = "Lunch", 4, K = "Snak2", 5, K = "Dinner", 6, K = "Snak3", 7, K = "Night", 8)
    Col = Switch(D = "Monday", 2, D = "Tuesday", 3, D = "Wednesday", 4, D = "Thursday", 5, _
    D = "Friday", 6, D = "Saturday", 7, D = "Sunday", 8)


    doc.Tables(1).Cell(Row, Col).Range = Nz(.Fields(j).Value, "")
    Next
    .MoveNext
    Loop
    End With


    appWord.Visible = True
    appWord.Activate


    End If


    Set doc = Nothing


    Set appWord = Nothing


    Exit Sub


    errHandler:


    MsgBox Err.Number & ": " & Err.Description


    End Sub

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    What are the errors - exact message? I've never tried to do this before.

    Why do you need to use Word? Why not Access report?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    I need to export data into a word table because the issue is to merge data from word with the data from access. Believe me is a complicated story..


    I know about access report but its not a good solution from this case. Anyway, i'v tried many things so i god many errors such as the attached
    Attached Thumbnails Attached Thumbnails error vba.png  

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    What line throws that error?

    I tried running the procedure and get error about 'communicating with OLE Server or ActiveX control'. Can't even get as far as you do.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Told you June7, i'm not familiar with vba... Could you help in order to build a new code in order to do that?

    Thanks again

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Since I can't work with your db, I would have to work with mine and anything I could do with my own db probably won't be very helpful to you.

    Even the expression in textbox to concatenate first and last names is not working. This is all very odd. Maybe it has something to do with the foreign language (Russian, Greek?) characters.

    Suggest you get rid of the error handler lines and let the debugger stop on the line that triggers the error message and tell me what line that is.

    If you are trying to export data from the subform, the code won't do that. It is using RecordsetClone of the main form.



    Advise that you not use spaces and special characters/punctuation in naming convention. Using %, (, ), etc in names can cause issues.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Good morning my friend June7,

    Yes, i'm using Greek lang and maybe that will be problem on your pc. You wrote: Suggest you get rid of the error handler lines and let the debugger stop on the line that triggers the error message and tell me what line that is.
    How can i do that?

    Thanks in advanced

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    You can comment out the lines that deal with error handler.

    Review link at bottom of my post for debugging guidelines.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Thanks June7, i will let you know

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Maybe this will help you. I did a very simple test of VBA code opening your Word document and populating cells of table.

    Private Sub testWord()
    Dim appWord As Object, doc As Object
    Set appWord = CreateObject("Word.Application")
    Set doc = appWord.Documents.Add CurrentProject.Path & "\" & DocName
    doc.Tables(1).Cell(2, 2).Range = "ABC"
    doc.Tables(1).Cell(2, 3).Range = "DEF"
    doc.Tables(1).Cell(2, 4).Range = "GHI"
    appWord.Visible = True
    appWord.Activate
    Set doc = Nothing
    Set appWord = Nothing
    End Sub

    Get that much to work then move on to using looping and recordset.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #13
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Good morning my friend June7,

    I tried to check last night the vba code but i'm getting the attached error. Is it possible for you to prepare a sample please ?

    Thanks in advance
    Attached Thumbnails Attached Thumbnails error.png  

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    No, not going to build a db for this simple code

    I didn't actually use that line in my testing. I used:

    Set doc = appWord.Documents.Open("C:\Users\June\Weekly Diet Plan.docx")

    You can try:

    Set doc = appWord.Documents.Open(CurrentProject.Path & "\Weekly Diet Plan.docx")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    gstylianou is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Dec 2013
    Posts
    167
    Ok, now is working.! Thanks.

    But, how can i collect the data from each day and meal type and then export then to word? As i saw, i must do something with the code in order to do that.
    Eg.
    doc.Tables(1).Cell(2, 2).Range = "ABC"doc.Tables(1).Cell(2, 3).Range = "DEF"
    doc.Tables(1).Cell(2, 4).Range = "GHI"

    Is it possible to give me a "hand" for that bro?

    Thanks in advanced

Page 1 of 3 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Export to Word Doc Table
    By ItsMe in forum Sample Databases
    Replies: 5
    Last Post: 07-27-2014, 09:49 AM
  2. Export to Word
    By dagwood in forum Import/Export Data
    Replies: 1
    Last Post: 05-09-2013, 05:20 PM
  3. Export report to Word
    By Lowell in forum Reports
    Replies: 1
    Last Post: 02-06-2013, 11:54 PM
  4. Export to Word
    By Monterey_Manzer in forum Import/Export Data
    Replies: 0
    Last Post: 12-20-2012, 02:06 PM
  5. Incorrect Subtotal after Export to Word
    By DatabaseIntern in forum Import/Export Data
    Replies: 3
    Last Post: 07-25-2012, 09:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums