Results 1 to 10 of 10
  1. #1
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    True to my moniker, I am now bumbling around with Word automation. I want to be able to open a Word document from an Access module, populate some parts of it with text from my Access tables, and then email it to the user.
    First things first. I think it makes sense to use early binding but I can't even get off the ground.
    My approach may be wrong so please correct me if I'm already off on the wrong foot but here is what I'm trying to do and the problems I've run into.
    I don't know if the user will have the reference set so I want to do that in the code. I found I can't have this code in the same module as the declarations of the objects I'll need (I get an error message when execution begins in the module) so...
    I have: "Private refWrd As Reference" right under the "Option Compare Database" line.
    In the Form_Open module I have: "Set refWrd = References.AddFromFile("C:\Program Files\Microsoft Office\OFFICE11\MSWORD.OLB")".
    This seems to work fine. When I check, the reference is on and when I click the button to initiate my document building code I no longer get an error on these declarations:
    Dim appWrd As New Word.Application
    Dim doc As Word.Document
    So far so good (I don't have any code in this module yet!) but I want to remove the reference when the user is done so that I can turn it on again the next time the form is opened, so I put this in the Form_Close module: "References.Remove refWrd" but I get the error message "Invalid procedure call or argument" when I try to close the form.
    What am I doing wrong?
    Thanks for any help you can give... all suggestions welcome!
    Thanks

  2. #2
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I.m bumbling around more than you. The forum seems very quiet??

    Are there any clues in this lot?

    http://www.google.co.uk/search?hl=en&q...earch&meta=


    Being logical, unlike software, but what happens if "Set refWrd = Nothing" is used. Only a long shot


    Regards

  3. #3
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Yes, it seems very quiet! Thanks for the suggestion. I was not able to find anything specific in your search results (I tried changing "set" to "remove" too). I tried searching a number of things earlier including this forum and Google Groups but couldn't find the answer. Every place where I have found anything it looks like what I already have.
    I tried what you suggested but it didn't remove the reference (i.e. if I go to Tools, References Word is still checked, and the open macro fails the next time I open the form).
    I'm probably missing something in the syntax but I don't see it.
    Several articles suggest late binding instead but I like having the Word object module exposed and late binding runs slower (according to what I read).
    Hopefully someone else will have another suggestion.
    Thanks

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    [quote name='VBA-Bumbler' post='773939' date='07-May-2009 02:13']I don't know if the user will have the reference set so I want to do that in the code.[/quote]

    A Reference setting is database specific not user specific. So if you set the Reference in the database then it will be set for any user of that database.
    There is a risk that the Reference might be broken or missing for some users (if they don't have the right version of Word), but I suspect you will have exactly the same problem with setting the Reference in code.

    When I use Word automation, which I do a lot, I just set the Reference in the database.
    Regards
    John



  5. #5
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Right you are! I checked in the db I was in and it was on. I closed the db and opened another without closing Access and it was off! This certainly makes life easier! Thanks for the tip.
    Yeah, I'm a little worried about the Word version thing but we are supposed to have a standard desktop here so I don't think it will be a problem until they start to roll out a new standard.
    Thanks so much for the info!

  6. #6
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    [quote name='VBA-Bumbler' post='774017' date='06-May-2009 17:24']Right you are! I checked in the db I was in and it was on. I closed the db and opened another without closing Access and it was off! This certainly makes life easier! Thanks for the tip.
    Yeah, I'm a little worried about the Word version thing but we are supposed to have a standard desktop here so I don't think it will be a problem until they start to roll out a new standard.
    Thanks so much for the info![/quote]The version can be an issue, but in general as long as paths to the object module are consistent, Access will usually adjust to what version of office the user has. Is your database split so that each user has their own front-end to a common backend? If not, consider doing that - otherwise you will have problems if users with different versions of Office try to use the same front-end at the same time.
    Wendell

  7. #7
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Wendell,
    Thanks for the tip. At this point I have been reasonably assured that we all have the same version but as soon as I find out that isn't the case, I will look into the split db idea. I haven't heard of this before so I don't have any idea what you mean but I'm sure if I have any questions I'll be able to get help on this great forum!
    Thanks

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Seeting and removing references in code is hard in Access, it's very likely to stop your code from running properly.

    With today's computers, late binding isn't much slower than early binding in most situations.
    You can develop your code using early binding, and when it's been thoroughly tested and debugged, you can convert it to late binding and remove the reference.
    See Post 526156

  9. #9
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts
    [quote name='VBA-Bumbler' post='774110' date='07-May-2009 08:22']... I will look into the split db idea. I haven't heard of this before so I don't have any idea what you mean but I'm sure if I have any questions I'll be able to get help on this great forum!
    Thanks[/quote]You might find our Split Database Tutorial helpful in understanding the benefits of splitting your database.
    Wendell

  10. #10
    3 Star Lounger
    Join Date
    Oct 2004
    Location
    USA
    Posts
    223
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Hans! I like that idea. The reference you gave cleared up a lot of my questions!

    Thanks Wendell! I'll check that out.

    Thanks

Posting Permissions

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