title: running select query in ms access 2007 vba and assign the resulting value to a textbox
body: <p>I need to run a sql query and the resulting value is assigned to a textbox in the form.
  I am using docmd.runsql sql to run this query.</p>
  
  <pre><code>Private Sub Form_Current()
  Dim SQL As String
  Dim db As Database
  Dim rs As DAO.Recordset
  
  If IsNull(Me.txtInstalledQuantity) Then
  SQL = "select count(tblequipmentbase.id)AS CountInstalledQuantity FROM (tblequipmentbase INNER JOIN     tblequipmentparts ON tblequipmentbase.id=tblequipmentparts.idconnect) INNER JOIN tblparts ON tblequipmentparts.idpart=tblparts.id where tblparts.id= " &amp; txtQueryID.Value &amp; ";"
  Set db = CurrentDb
  Set rs = db.OpenRecordset(SQL)
  DoCmd.RunSQL SQL
  Me.txtInstalledQuantity = rs!CountInstalledQuantity
  Set rs = Nothing
  Set db = Nothing
  End If
  End Sub
  </code></pre>
  
  <p>The error is in the runsql command.</p>