+ Reply to Thread
Results 1 to 4 of 4

Handling SPACE in [SQLstatement] argument during mailmerge

  1. #1
    Registered User
    Join Date
    07-31-2012
    Location
    Hong Kong
    MS-Off Ver
    Excel 2016
    Posts
    6

    Question Handling SPACE in [SQLstatement] argument during mailmerge

    Below is my vba code for calling a mailmerged word doc with data filtred for any cell under the [Status] column that contains the value 'Pending report'.

    These code resulted in infinite loop of error "Excel is waiting for another application to complete an OLE action".

    However, if the value to be matched is changed to one that does NOT contain any SPACE e.g. WHERE [Status] = 'Done', everything's fine.

    I attempted to handle the SPACE with the following ways but to no avail:
    • 'Pending'&' '&'report'
    • [Pending report]
    • '"Pending report"'
    • 'Pending%report'
    • ""Pending report""

    I have try googling the solution for the whole day Any help would be much appreciated!

    Please Login or Register  to view this content.
    Last edited by Zlll; 11-06-2017 at 07:42 AM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Handling SPACE in [SQLstatement] argument during mailmerge

    Try

    Please Login or Register  to view this content.
    Martin

  3. #3
    Registered User
    Join Date
    07-31-2012
    Location
    Hong Kong
    MS-Off Ver
    Excel 2016
    Posts
    6

    Re: Handling SPACE in [SQLstatement] argument during mailmerge

    Quote Originally Posted by mrice View Post
    Try

    Please Login or Register  to view this content.
    Thanks but still doesnt work...
    I guess I might at the end remove the space from the values of those affected cells.

  4. #4
    Forum Expert macropod's Avatar
    Join Date
    12-22-2011
    Location
    Canberra, Australia
    MS-Off Ver
    Word, Excel & Powerpoint 2003 & 2010
    Posts
    3,726

    Re: Handling SPACE in [SQLstatement] argument during mailmerge

    The error message has nothing to do with your SQL syntax or an infinite loop but with the fact your macro is waiting for someone to respond to the SQL prompt Word generates when opening a mailmerge main document - which is why you're getting that particular error message.

    The following macro shows how you might prevent that issue arising - and generate a separate output file for each merged record as a Word document and/or pdf. You could, of course, omit that extra functionality.
    Please Login or Register  to view this content.
    Last edited by macropod; 11-06-2017 at 09:02 AM.
    Cheers,
    Paul Edstein
    [Fmr MS MVP - Word]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Shift+Space and Ctrl+Space shortcuts intermittently working
    By yumyumdimsum in forum Excel General
    Replies: 8
    Last Post: 10-14-2017, 11:54 AM
  2. Using an IF argument & COUNTIF argument in the same cell formula
    By TommyK25 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-14-2013, 08:52 AM
  3. [SOLVED] ByRef argument type mismatch / Passing array as a function argument
    By pzling in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2012, 06:23 PM
  4. [SOLVED] Handling imported dates, some with a trailing space
    By JonnieB in forum Excel General
    Replies: 5
    Last Post: 10-04-2012, 09:51 AM
  5. Replies: 3
    Last Post: 04-28-2010, 05:54 PM
  6. [SOLVED] Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 AM
  7. Error handling with a handling routine
    By ben in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-15-2005, 11:06 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1