Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 31
  1. #16
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Ooops, I didn't even see the double C:\

    Need to remove comma from the CreateObject call. The code is not closing Word app. Make following changes:

    Set appWord = CreateObject("Word.Application")
    Set docm = appWord.Documents.Open(strDocmName)
    appWord.Visible = True
    blnQuitWord = True

    Remove:
    cnn.Close




    A file picker is good idea. As is, user must enter the file suffix (.docm) as well as not commit any spelling error. https://www.accessforums.net/program...ame-39963.html


    Might want to review link at bottom of my post on debugging techniques.
    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.

  2. #17
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    A file picker is good idea. As is, user must enter the file suffix (.docm) as well as not commit any spelling error.
    The code I used in post #12 has the docx extension hardcoded. Forgot about the macro thing. When I hard coded the extension, that is when I started thinking about the file picker.

    appWord.Quit should close the word doc object.

  3. #18
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    The Quit is in there, but with a conditional that wasn't working.
    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.

  4. #19
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    It seems the error trapping was there to set the Boolean to true and use CreateObject in the event GetObject failed. This explains a lot. The error on GetObject must have been producing a different error code.

  5. #20
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Good point. I changed the code back to GetObject and it works. It's the correct err number.

    Set appWord = GetObject(, "Word.Application")
    Set docm = appWord.Documents.Open(strDocmName)
    appWord.Visible = True
    Set rst = CurrentDb.OpenRecordset("tblContracts")

    So the only real change I had to do was remove cnn.Close. That leaves primary suspect for cause of issue is incorrect input of file name. I had to change the path/filename for my file location so I used a static reference in code.
    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.

  6. #21
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    .....That leaves primary suspect for cause of issue is incorrect input of file name. I had to change the path/filename for my file location so I used a static reference in code.
    Me thinks the same. Except, the error trapping should have explained word doc not found. Suggest OP uses original code and leaves error trapping alone. And uses correct file name with extension, of course.

    I downloaded DB.
    Pasted code from post #1 into Module
    Adjusted paths
    Compact and repair
    Opened Form
    Clicked button
    Successful Import

  7. #22
    maxmd29 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    12
    Quote Originally Posted by ItsMe View Post
    Are you interested in my suggestion in post #12?
    Sorry I was out of the office all day yesterday and missed your previous post. I put in the new code you suggested. A run-time error 424: object required occurred at ' Set docm = appWord.Documents.Open(strDocmName & ".docm") '

  8. #23
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Check out June's comment and my post in post #21. Something goofy is happening with the path for your file. Additionally, post #12 should isolate the path and file extension issue from any other possible issue. Isolating the code in post #12 in a separate click event for the sole purpose of opening the macro enabled word doc should help you to troubleshoot the path issue.

  9. #24
    maxmd29 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    12
    Quote Originally Posted by ItsMe View Post
    Me thinks the same. Except, the error trapping should have explained word doc not found. Suggest OP uses original code and leaves error trapping alone. And uses correct file name with extension, of course.

    I downloaded DB.
    Pasted code from post #1 into Module
    Adjusted paths
    Compact and repair
    Opened Form
    Clicked button
    Successful Import
    So I have read through both your observations and I think I have implemented everything though I am still coming up with the same error. I am thinking though that this has to be some thing on my input error if you have got the code to work. Whent he dialog box pops up to input the name of the document I have been inputting: "[document name].docm"

  10. #25
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    If you look at the code in post#12, the extension is included. You would only need the name "Me", in the input box if you are using the sample file you previously uploaded.

  11. #26
    maxmd29 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    12
    Quote Originally Posted by ItsMe View Post
    If you look at the code in post#12, the extension is included. You would only need the name "Me", in the input box if you are using the sample file you previously uploaded.
    Okay, the code from #12 works fine. It opens the document without any incidents. I tried applying that code to the original module and error popped up that said I must select a valid word document.

  12. #27
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows XP Access 2003
    Join Date
    Aug 2013
    Posts
    7,862
    Considering both June and I were able to successfully implement the original code from post #1, there is not a need to incorporate the code from post #12. Correcting the file path and perhaps hardcoding the word doc extension should suffice. Ultimately, some file picker code would be best to assign the path to your string variable.

    Let us know how you would like to proceed and post your latest code revision. Please indicate precisely where the code failed.

  13. #28
    maxmd29 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    12
    Okay I think I am going to attempt to incorporate some file picker code mention in #16. I do have a question though about the code differences in #12 to my original code: Why is it that your code in #12 opens the file whereas my original code returns a not a valid word document error?

  14. #29
    maxmd29 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2013
    Posts
    12
    Quote Originally Posted by ItsMe View Post
    Considering both June and I were able to successfully implement the original code from post #1, there is not a need to incorporate the code from post #12. Correcting the file path and perhaps hardcoding the word doc extension should suffice. Ultimately, some file picker code would be best to assign the path to your string variable.

    Let us know how you would like to proceed and post your latest code revision. Please indicate precisely where the code failed.
    Actually never mind!! I realized the few differences in your codes and it actually worked. I changed "Dim appWord, docm" as objects and that seemed to be the fix I needed. I can not thank you both enough for your help and working with me. It must have taken a good deal of patience to deal with my limited knowledge and understanding of VBA.

    Now would it be pushing it to wonder if I can do the inverse and export the data from the form into a pre-defined word document? I have been able to export as a pdf, but I have a word form that is more visually appealing that I would like to use as a final document.

    Max

  15. #30
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Yes, that is possible.

    Probably just have to swap the field references.

    Why using Word instead of 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.

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

Similar Threads

  1. Replies: 3
    Last Post: 12-13-2013, 07:03 AM
  2. VBA Code Returning Error Run Time Error 3061
    By tgwacker in forum Access
    Replies: 2
    Last Post: 11-24-2013, 11:00 AM
  3. Replies: 6
    Last Post: 04-26-2013, 03:51 PM
  4. Run-time error on import (Split DB)
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 03-15-2011, 06:43 AM
  5. Duplicate Check code with Run-Time error '3079'
    By viper in forum Programming
    Replies: 5
    Last Post: 10-18-2010, 10:12 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