VBA variable in OpenRecordSet query RRS feed

  • Question

  • Hi Folks -

    I'm having a brain fart.

    I'm trying to replace the search string in the following line of code:

    Set sRS = dbs.OpenRecordset("Select * from [MDM_Partner_Detail_Reference] where [Name] like ""PTP*""", dbOpenDynaset)

    Instead of PFP* I want to use a variable.  Above that line of code, I have a variable set as follows:

    strMask = "PTP*"

    But when I try to add it to the query I can't get it to return. Can someone show me how to add it to the query?

    I've tried like  " & strMark & """ with no luck, as well as other variants.

    Thank you!

    • Edited by cdtakacs1 Tuesday, March 5, 2019 10:17 PM
    Tuesday, March 5, 2019 10:15 PM


  • Hi. Did you try something like?

    Set sRS = dbs.OpenRecordset("SELECT * FROM TableName WHERE Field Like """ & strMask & """", dbOpenDynaset)

    • Marked as answer by cdtakacs1 Wednesday, March 6, 2019 10:14 AM
    Tuesday, March 5, 2019 10:28 PM

All replies