【问题标题】:how to query access database and retrieve values based on some criteria's from excel vba如何根据excel vba中的某些条件查询访问数据库和检索值
【发布时间】:2012-03-08 01:33:33
【问题描述】:

能否请您帮忙从 excel vba 访问数据库查询

我的算法如下:


打开连接以访问数据库

选择 table1.column1, table1.column2, table1.column3 其中 table1.column3.value = “x” and table1.column2.value = “y”

切换案例 1:如果 没有从访问数据库中找到符合条件的记录

插入一些值等等……

切换案例 2:如果 从访问数据库中找到符合条件的记录

无需任何操作

切换案例 3:如果发现 记录与访问数据库中的条件不匹配

应该在 excel vba 中的 datagridview 中显示值

不应允许插入值


请帮助我使用 excel vba 所需的代码

谢谢 普拉布 M

【问题讨论】:

  • 搜索[ms-access] [excel] ado
  • 查看此链接。它将为您提供有关如何进行的基本思路。 stackoverflow.com/questions/9083232/…
  • 谢谢老兄,但你能帮我如何根据从访问数据库中找到的记录或不符合条件的记录来使用 switch case
  • @Prabu Mike:奇怪,我错过了这个问题。会要求您在回复时使用“@”和我的名字,就像我为您所做的那样,以便我得到您回复的暗示:) 您还在寻找解决方案吗?

标签: ms-access excel ms-access-2007 vba


【解决方案1】:

注意case3case1 是相似的

你可以使用这个代码

    Dim recSet As Recordset
    Set recSet = CurrentDb.OpenRecordset("Select table1.column1, table1.column2,"_ 
           & "table1.column3 where table1.column3.value = 'x' and table1.column2.value = 'y'")
    If recSet.EOF Then 'No records matching criteria
        'Do something
    Else 'There was records found
        'Do Something else
    End If

【讨论】:

    猜你喜欢
    • 2022-01-16
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多