title: How to save the result of a SQL query into a variable in VBA?
body: <p>I want to execute a select statement and put the result of it (which is only 1 record with 1 value) in a variable. </p>
  
  <p><strong>This is in VBA code in access.</strong></p>
  
  <pre><code>Private Sub Child_Click()
     Dim Childnummer As Integer
     Dim childnaam As String
     Childnummer = Me.Keuzelijst21.Value
     DoCmd.Close
     DoCmd.OpenForm "submenurubrieken", acNormal, , " rubrieknummer = " &amp; Childnummer &amp; ""
     childnaam = rubrieknaamSQL(Childnummer)
     Forms!submenurubrieken.Tv_rubrieknaam.Value = childnaam
  End Sub
  
  Public Function rubrieknaamSQL(Child As Integer)
     Dim rst As DAO.Recordset
     Dim strSQL As String
     strSQL = "SELECT rubrieknaam FROM dbo_tbl_rubriek where rubrieknummer = " &amp; Child &amp; ""
     Set rst = CurrentDb.OpenRecordset(strSQL)
  End Function
  </code></pre>