【问题标题】:How can I declare the variable from the list in ADODB query?如何从 ADODB 查询的列表中声明变量?
【发布时间】:2021-04-19 08:30:47
【问题描述】:

我有一个包含 100 个变量的选项列表:我想单击此列表并在我的 ADODB 查询中使用 tis 变量: 我不知道如何在查询中声明从列表中选择的变量(例如,如果我选择 LFG -CORTAGE - 999)。

我的清单: .com/cfm5G.png

【问题讨论】:

  • 变量名中不允许有空格,也不能有“-”字符...尝试使用“_”。 LFG_CORTAGE_999 As String 应该没问题。
  • 谢谢,但这不是我想要的。 )
  • 我想点击列表并在我的 ADODB 查询中使用选择的变量
  • 我有 100 个变量在列表中
  • 所以它可能是 LFG_CORTAGE_999 或 COURTAGE-13 或 LPP 或 LKL ...

标签: sql excel vba adodb


【解决方案1】:

请复制工作表代码模块中的下一个代码并开始更改下拉选项。但是你的代码有一个问题:参数'cnn_Pegase'没有声明和定义。

Option Explicit


Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address(0, 0) = "E15" Then
        N_CG_bulletin_de_souscription Target.Value
    End If
End Sub

Sub N_CG_bulletin_de_souscription(strQ As String)
    'Please, note that the parameter 'cnn_Pegase' is not declared and defined.
    'Properly declare it and give to it the necessary value, before running the code...
    Dim RECSET As New ADODB.Recordset
    RECSET.Open "select cond_gene.s_no_cg from db_dossier sousc, db_protocole proto, db_tiers tiers, db_cond_gene cond_gene, dr_protocole_cg protocole_cg, db_personne pers, db_contrat cont " & _
                " where sousc.no_police = '" & strQ & "' and sousc.cd_dossier = 'SOUSC' and sousc.lp_etat_doss not in ('ANNUL','A30','IMPAY') and sousc.is_dossier = cont.is_dossier and cont.is_cg = cond_gene.is_cg", cnn_Pegase, adOpenDynamic, adLockBatchOptimistic
        If Not RECSET.EOF Then
            Worksheets("1 - Feuille de Suivi Commercial").Range("N_CG_bulletin_de_souscription_C11").Value = RECSET.fields("s_no_cg").Value
        Else
            Worksheets("1 - Feuille de Suivi Commercial").Range("N_CG_bulletin_de_souscription_C11").Value = ""
        End If
    RECSET.Close
End Sub

【讨论】:

  • 谢谢,当您说“更改下拉选项”时,您的意思是列表吗?声明了 cnn,我只是没有把它放在我的消息中:)
  • @Marie:但你所说的“列表”不就是通过单元格数据验证获得的下拉列表吗?如果是,答案是肯定的。请尝试更改其值并查看发生了什么...
  • 您好,抱歉,最后一个问题。 )) 也许你知道如何从数据中检索最后一位数字:如果我的变量是 LKM - 999 我只想有 999,有一些函数,如 SCAN (strQ,1,-1)?
  • @Marie:很高兴我能帮上忙!你可以使用999 = split("LKM - 999", " - ")(1)...
  • 我可以这样做吗:N_CG_bulletin_de_souscription Target.split("Value", " - ")(1)
猜你喜欢
  • 1970-01-01
  • 2010-12-02
  • 2022-08-04
  • 1970-01-01
  • 2017-04-21
  • 1970-01-01
相关资源
最近更新 更多