• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Function returns zero if no data found

I need this user defined function to return a zero in the cell if no data was found in the .mdb

Const MDB = "C:\rubyfiles\tanks\gasdata.mdb"

Function getGASdata(pstrQuery As String)
    getGASdata = DAO.DBEngine.OpenDatabase(MDB, , True).OpenRecordset(pstrQuery)(0)
End Function


0
mweidner
Asked:
mweidner
1 Solution
 
Wayne Taylor (webtubbs)Commented:
Hi mweidner,

Try this....

    Function getGASdata(pstrQuery As String)
        Dim rs As Recordset
        Set rs = DAO.DBEngine.OpenDatabase(MDB, , True).OpenRecordset(pstrQuery)
        If rs.EOF And rs.BOF Then
            getGASdata = 0
        Else
            getGASdata = rs(0)
        End If
        Set rs = Nothing
    End Function

Regards,

Wayne
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now