Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2004
    Posts
    1

    Unhappy Unanswered: HELP, I have a problem, n my work is due in on friday

    I need to submit my coursework in on friday, I have made a mail merge , but I want to create a button on a form that will automatically run the document, so is it possible for somebody to show what script/code i need to use in a module. Please.

    Thank you

  2. #2
    Join Date
    Feb 2004
    Location
    CT,USA
    Posts
    250

    Talking

    May the force be with you, padawan Access learner.

  3. #3
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    25
    Did you ever get a solution for this? I am having the same problem myself. What I did instead was to create a command button with a hyperlink to that document and let them select what data they want to see using a check box and then use the onClick event with command button. It works just as good but having them click only one button would be better.

    Caoimhin

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    What exactly are you trying to do? Open a Word document? Or something more complex like assign the record source etc?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    25
    I have the word document set up for mail merge and the record source assigned so what I want it to do is on my form frmCreateLetters, have a command button, and when clicked it opens the word document and updates the data in a table I have details in such as name address etc. What I have in my code is:
    1- its run a query to update the table temp table
    2- Open the word document and display the updated names and addresses.

    What happens is that the mail merge document wont update with new values.

    Code:
    DoCmd.OpenQuery "qryPrintLetter"
    
     
    
    Dim appWord As Object
    
     
    
    Set appWord = CreateObject("Word.Application")
    
    appWord.Visible = True
    
     
    
    Dim objDoc As Object
    
    Set objDoc = appWord.Documents.Open("C:\Databases\Access Databases\MergeLetters")
    The query 'qryPrintLetter' updates value in in a table called 'TempMembers' which the document mail merges with. When you click the command button to perform this code it opens the word document but the names and address dont appear. It also doesnt ask you if you want to perform the mail merge SQL query.



    Any help would be greatly appreciated.

    Thanks.

  6. #6
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Some advice - use early binding if at all possible.
    Eh?
    Tools-> References-> Microsoft Word x0.0
    Change the code to:
    Code:
    DoCmd.OpenQuery "qryPrintLetter"
    Dim appWord As New Word.Application appWord.Visible = True Dim objDoc As Word.Document Set objDoc = appWord.Documents.Open("C:\Databases\Access Databases\MergeLetters")
    BTW - shouldn't your doc path end in .doc or something?

    Anyhoo - if you early bind you can make use of Intellisense.

    My mail merges don't seem to need this (I set the recordsource dynamically) but perhaps you need:
    Code:
    objDoc.MailMerge.Execute
    ??
    Testimonial:
    pootle flump
    ur codings are working excelent.

  7. #7
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    441
    I'll disagree, I use late binding for all automation, but then I have to have the same stuff working on 2000-2003.

    But what triggered my reply here, is the usage of implicit instantiation. If you know what you're doing, it's probably OK elsewhere, but never, ever in automation. Be explicit:

    Dim appWord As Word.Application
    Set appWord = new Word.Application

    I think there's some benefits of using CreateObject also on early binding. See http://support.microsoft.com/kb/244264/ for more info.
    Roy-Vidar

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Yes - I can see the point about not using Dim x As New y. To be honest - that is mainly lazyness - I knew the object is not actually initialised until it is actually used (unlike .Net) but hadn't followed that through to the debugging issue that you then don't know if it is the method or the instantiation that has gone wrong. I will change my habbits there.

    I always use early binding with no problems (XP -> 2003 clients). To be fair I didn't cover the gotcha - make sure you are referencing the oldest (including service packs) version of the app that any of your clients will be using - that in itself might mean an install. What the article doesn't mention is that late binding requires a lookup of the method DISPID (rather than the VTable that early binding does at compile time) which can have performance implications (especially in loops). It also allows you to trap lots more errors at design time.

    I use New over CreateObject as the latter is no longer supported in .NET - I just don't want to confuse myself. I must confess my COM book implied that they are different ways of calling the same process whereas the article suggests otherwise.

    Anyway - there are pros and cons to both. You were correct to pull me up for suggesting that early binding is the "correct" way though
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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