【问题标题】:VBA: How to assign sql statements in combobox items and execute on button click?VBA:如何在组合框项目中分配 sql 语句并在按钮单击时执行?
【发布时间】:2018-09-23 08:36:52
【问题描述】:

这是我的目标场景,

  1. 单击单选按钮,如果为真则在组合框中显示项目(来自 db)
  2. 选择组合框中的项目
  3. 点击OK按钮,运行SQL语句生成新工作簿

我的问题是,有没有更好的方法在组合项中分配特定的 sql 语句?

    If ComboBox1.Text = “Desktop” Then
       'query = "Select * from Desktop"
        call DesktopList
    Else If ComboBox1.Text = “Laptop” 
      'query = "Select * from Laptop"
       call LaptopList
    End If

【问题讨论】:

  • 您的问题是如何分配还是有更好的方法?
  • 如果有更好的方法,谢谢回复
  • 在变量中获取 ComboBox1 的值并在查询中调用该变量。 ComboSelectValue = ComboBox1.Text 之类的内容,然后您可以在查询中将其用作 query = select * from ComboSelectValue。让我知道这是否有帮助。
  • 我现在明白了。谢谢@Sid29,我错过了那个。
  • @martiantrello 没问题。我已将其作为答案。如果你愿意,你可以接受。

标签: vba if-statement combobox


【解决方案1】:

在变量中获取 ComboBox1 的值并在查询中调用该变量。

类似于 ComboSelectValue = ComboBox1.Text

然后你可以在你的查询中使用它作为

查询 = 从 ComboSelectValue 中选择 *

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-01
    • 2017-09-29
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 1970-01-01
    • 2012-10-23
    • 2015-03-26
    相关资源
    最近更新 更多