您好我只需要在ACCESS的AQ_SEG表中的字段SEG_OPE_REMARQ中的某处包含条件= RS
我只需要获得RS部分
其余代码中的所有内容都可以正常工作
Sub GetNumbersSigeqR()
'Get Retrait SIGEQ de AQ_SEG_EPEL_XX.mdb.mdb
Dim mrc As String
Dim retrait As String
mrc = Val(Range("D2").Value)
If Len(mrc) < 2 Then
mrc = "0" + mrc
End If
retrait = "AQ_SEG_EPEL_" + mrc + ".mdb"
Dim folderPath As String
folderPath = Application.ActiveWorkbook.Path
Dim cn As Object
Dim rs As Object
Dim strSql As String
Dim strConnection As String
Set cn = CreateObject("ADODB.Connection")
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & folderPath & "\" & retrait
strSql = "SELECT Count(*) FROM AQ_SEG ;"
cn.Open strConnection
Set rs = cn.Execute(strSql)
Sheets("T9Cp1").Range("G97").Value = rs.Fields(0)
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
答案 0 :(得分:1)
我仍然不完全确定我理解这个问题(正如你提到包含RS的字段,但你也有一个名为RS的对象)但是根据你的回答和原始问题,以下查询对于strSQL
,只计算字段包含“RS
”的行:
strSql = "SELECT Count(*) FROM AQ_SEG WHERE SEG_OPE_REMARQ LIKE '%RS%';"