dcsimg
Results 1 to 12 of 12

Thread: Error when adding fields to MailMerge

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2019
    Posts
    25

    Error when adding fields to MailMerge

    VB is throwing the following error. I've researched but cannot find an answer. Every example for MailMerge uses this.


    Name:  MMERROR.jpg
Views: 95
Size:  21.2 KB

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,410

    Re: Error when adding fields to MailMerge

    Are you sure that's HOW they used it? Or was it used slightly differently? Can you post a link to an example where you saw it used? (or more than one).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2019
    Posts
    25

    Re: Error when adding fields to MailMerge

    The examples have it like this

    Code:
                .Add oApp.Selection.Range, "Contact_Name"
                oApp.Selection.TypeParagraph
    However, that will not compile.

    Link: https://docs.microsoft.com/en-us/off...mailing-labels
    Last edited by PMHA; Aug 6th, 2019 at 09:26 AM.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,410

    Re: Error when adding fields to MailMerge

    So if the example was this:
    Code:
    .Add oApp.Selection.Range, "Contact_Name"
    Why are you doing this:
    Code:
    .Add (oApp.Selection.Range, "Contact_Name")
    Because that changes how the call is made...

    -tg
    Also... in the future, when you post code, post code using the [code][/code] tags... don't post screenshots... 1) the forum does funny things with images and 2) it makes it hard to read and we can't copy it for example purposes.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2019
    Posts
    25

    Re: Error when adding fields to MailMerge

    As I said. That format will not compile. Throws this error:

    'Method arguments must be enclosed in parentheses'

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,410

    Re: Error when adding fields to MailMerge

    Ahhh... I get it now... that's because the example on that page is VB6... not .NET ... You need to add references to the InterOp objects for Word in order to make things work. You'll then get the advantages of early binding and the calls will work once corrected (such as adding parenthesis where needed). Search for .NET MS Office interop ... that should help you get in the right direction.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2019
    Posts
    25

    Re: Error when adding fields to MailMerge

    Yep. I figured it out. Added proper reference to Word.Interops.

    Thanks for help.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jul 2019
    Posts
    25

    Re: Error when adding fields to MailMerge

    Ok. Now the issue is that it does not print correctly for Avery 5160. Apparently there us some mfr code I need but I can't find it anywhere.

  9. #9
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,427

    Re: Error when adding fields to MailMerge


  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jul 2019
    Posts
    25

    Re: Error when adding fields to MailMerge

    What I need is the value to use in VB. That link is for creating it directly in word.

  11. #11
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,427

    Re: Error when adding fields to MailMerge

    value to use in VB
    There is no "value" to use. Automating Word to do the printing is the easy way to go. If you want the hard way - in case Word is not available - here are some possibly useful links:

    http://www.vbforums.com/showthread.p...hipping-Labels

    https://www.neodynamic.com/ND/FaqsTi...rodid=0&sid=99

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jul 2019
    Posts
    25

    Re: Error when adding fields to MailMerge

    Of course there is a value. The AVERY number goes in the name attribute. Apparently, there is a problem with the 5160 in VB. There is supposed to be a value that will make it correct. That is what I am needing.

    Code:
            oApp.MailingLabel.CreateNewDocument(Name:="5160", Address:="", AutoText:="MyLabelLayout", LaserTray:=Nothing)

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width