title: Pass through query with userinput in access form
body: <p>I have Access front end which is powered by SQL Server in backend.</p>
  
  <p>I made a form which requires user input, based on the input it should run a pass through query and should display result in the subform. I have read on internet this cannot be done through sql command and it requires sql coding to be wrapped in VBA coding.</p>
  
  <p>I have made a code this like this:</p>
  
  <pre><code>Private Sub id_AfterUpdate()
  Dim MyDb As Database, MyQry As QueryDef
  Set MyDb = CurrentDb()
  Set MyQry = MyDb.CreateQueryDef("")
  
  MyQry.Connect = "ODBC;DSN=mikecollections;UID=***;PWD=****;DATABASE=mikecollections;"
  MyQry.SQL = "select currency.tb_coins.id,documenttype,documentsubtype,documentname" &amp; _
              "from currency.tb_coins" &amp; _
              "inner join collectibles.tb_documents on tb_coins.id=collectibles.tb_documents.prodid" &amp; _
              "where currency.tb_coins.id=[forms]![test_form]![id]"
  
  End Sub
  </code></pre>
  
  <p>This code should fire after I enter value in the id field in the form, but nothing happens. I do not know how to make this code work. Im new to SQL and VBA, Pls help!</p>