Results 1 to 8 of 8
  1. #1
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94

    Access SQL queries with LIKE condition as Word document data source

    Hi there,



    i use various SQL queries from my database as data source for some Word documents that act as forms. Usually it's simple SQL queries with conditions such as whatever.type=6 or whatever.field is not null. Though I've noticed that when I use a condition such as table.field like '*string*' the results show perfectly on Access, but list appears empty on word when using that query as data source.

    Is that a normal behaviour? If so how can I use a query searching for a certain pattern in one field as my data source for Word?

    Thank you all so much!

  2. #2
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Not sure what\how this would happen but you can try to use the InStr() function:
    Code:
    SELECT ......FROM tblYourTable WHERE InStr([YourField],"StringToSearchFor")>0
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    but list appears empty on word when using that query as data source.
    I presume you are running this query in word? If so, it may be you are using the ADO recordset method which uses % rather than *. To use the dao method, in your vba window ensure the microsoft DAO library is selected and you have dimmed your recordset as DAO.recordset

  4. #4
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    Quote Originally Posted by Ajax View Post
    I presume you are running this query in word? If so, it may be you are using the ADO recordset method which uses % rather than *. To use the dao method, in your vba window ensure the microsoft DAO library is selected and you have dimmed your recordset as DAO.recordset
    Thank you so much!

    I'm using the query stored in the DB as mail merge data source for a Word document. Changing the like wildcard to % does the trick. Then again, where should I add the DAO library? I did so in Word and the * wildcard still fails. Can't add it to the access db cause it gives an error about compatibility issues.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Then again, where should I add the DAO library? I did so in Word..
    It is now not clear to me where your query is or where it is being called from. Wherever it is, you need to 'type' your recordset as

    dim rs as ADO.recordset
    or
    dim rs as DAO.recordset

  6. #6
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    The query is on the Access DB, has been created through the sql view of the 'Query design' access functionality. I don't see any way to change its type on the object properties or anywhere else. Then that query is used as mail merge data source for a word document (mailings->select recipients->use an existing list, then selecting the DB and the query).

    Anyway, since the queries I use for the word documents are used only for that purpose I'll make sure I use % instead of * as a wildcard when searching patterns on fields. That's enough to solve my problem.

  7. #7
    Gicu's Avatar
    Gicu is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You should also check that your Access client is not set to use SQL Server compatible syntax - ANSI 92 version (under File\Options\Object Designers).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    Quote Originally Posted by Gicu View Post
    You should also check that your Access client is not set to use SQL Server compatible syntax - ANSI 92 version (under File\Options\Object Designers).

    Cheers,
    Yep, that is unchecked.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 01-27-2022, 04:54 PM
  2. Replies: 3
    Last Post: 06-27-2017, 12:06 PM
  3. Replies: 2
    Last Post: 07-27-2016, 01:29 PM
  4. Replies: 5
    Last Post: 05-18-2015, 08:08 AM
  5. Replies: 8
    Last Post: 07-29-2014, 06:41 PM

Tags for this Thread

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