Return to Snippet

Revision: 24434
at March 1, 2010 16:07 by CaptainProton


Initial Code
Private Function getResultFromSQL(sql As String) As Variant
  Dim recordset As recordset
  
  Set recordset = CurrentDb.OpenRecordset(sql)
  
  If (Not recordset.EOF) _
   And (Not recordset.BOF) Then
    recordset.MoveFirst
    getResultFromSQL = recordset(0)
    
    Set recordset = Nothing
    Exit Function
  End If
  
  Set recordset = Nothing
  getResultFromSQL = Nothing
End Function

Initial URL

                                

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

Initial Title
getResultFromSQL(String) As Variant

Initial Tags
sql, query

Initial Language
Visual Basic