• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

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