How to use parameterized query in Excel using column as parameter?

后端 未结 2 1113
庸人自扰
庸人自扰 2020-11-29 10:33

I am trying to develop a spreadsheet that can locate corresponding records in an external data source. So, let\'s say I have Column A with a list of identity values. I wan

2条回答
  •  时光说笑
    2020-11-29 11:11

    So to do this I would create a UDF and have the backend of that function connecting to your access database. Something like this:

    Public Function countMyTable(IDValue As Double) As Long
    'Requires:// Microsoft Access 16.0 Object Library
    'Requires:// Microsoft Office 16.0 Access database engine Object Library
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Set db = Access.DBEngine.Workspaces(0).OpenDatabase(DBFilePath, False, False)
    Set rs = db.OpenRecordset("SELECT COUNT(1) FROM MyTable WHERE IDValue = " & IDValue, dbOpenSnapshot)
    rs.MoveLast
    countMyTable = rs(0)
    db.close
    End Function
    

    Hope this helps, TheSilkCode

提交回复
热议问题