title: How to put a variable in a like statement in vba?
body: <p>I'm trying to get data from a db access using sql statement Like with a variable</p>
  
  <p>The variable is a string "mrcTrx"</p>
  
  <p>Go to the ******* in commentary to get direct to the point.</p>
  
  <p>I know its not a big deal but I cannot find the answer thank you!</p>
  
  <p>The rest of the code is fine cuz if I a put a value for exemple '05' the code works perfectly</p>
  
  <pre><code>Sub GetMun()
  
            Dim cn As Object
            Dim rs As Object
            Dim intColIndex As Integer
  
            Dim TargetRange As Range
            Dim mrcMun As String
            Dim mrcTrx As String
            Dim reg As String
  
            mrcTrx = Val(Range("D2").Value)
  
              If Len(mrcTrx) &lt; 2 Then
  
                  mrcTrx = "0" + mrcTrx
  
              End If
  
  
  
              Debug.Print mrcTrx
  
            Dim totalGP As Integer
            Dim debutRng As String
  
            totalGP = Sheets("T1").Range("G247").Value
  
            debutRng = "D" &amp; 250 + totalGP
  
  
          mrcMun = "D:\FicheMacro\Mun\PréparationTRX par Munic.mdb"
  
          'On Error GoTo ErrorGetGPmun
  
          Application.ScreenUpdating = False
  
          Set TargetRange = Sheets("T1").Range(debutRng)
  
          Set cn = CreateObject("ADODB.Connection")
          cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &amp; mrcMun
  '*******
         Set rs = CreateObject("ADODB.Recordset")
          rs.Open "SELECT MUNIC FROM Munic_en_MAJ_par_MRC WHERE MRC LIKE ' &amp; mrcTrx &amp; ' ", cn, , , adCmdText
  
  
              TargetRange.CopyFromRecordset rs
  
  
  
        Application.ScreenUpdating = True
  
  
       rs.Close
      Set rs = Nothing
       cn.Close
       Set cn = Nothing
  
     Exit Sub
  
  
  
  ErrorGetGPmun:
  
      MsgBox "Valider le type de trx et l'entête de la T1", vbExclamation, "La Fiche! GP"
  
  
  End Sub
  </code></pre>