如何在ADODB查询中声明列表中的变量



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

我的列表:.com/cfm5G.png

请复制工作表代码模块中的下一个代码,并开始更改下拉选项。但代码中有一个问题:参数"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

最新更新