Posted By

CaptainProton on 03/01/10


Tagged

sql query access


Versions (?)

getResultFromSQL(String) As Variant


 / Published in: Visual Basic
 

This method runs a SQL query and returns the first result (the query is expected to return exactly one record and one field).

  1. Private Function getResultFromSQL(sql As String) As Variant
  2. Dim recordset As recordset
  3.  
  4. Set recordset = CurrentDb.OpenRecordset(sql)
  5.  
  6. If (Not recordset.EOF) _
  7. And (Not recordset.BOF) Then
  8. recordset.MoveFirst
  9. getResultFromSQL = recordset(0)
  10.  
  11. Set recordset = Nothing
  12. Exit Function
  13. End If
  14.  
  15. Set recordset = Nothing
  16. getResultFromSQL = Nothing
  17. End Function

Report this snippet  

You need to login to post a comment.