请问怎么把SQL语句 Select 得到的内容赋值给一个单元格
PrivateSubWorksheet_Change(ByValTargetAsRange)IfTarget.Count>1ThenExitSubIfTarget.Col...
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column > 1 Then Exit Sub
If Target = "" Then Exit Sub
Dim cnn As Object, SQL$
Dim myPath As String
Set cnn = CreateObject("ADODB.Connection")
myPath = ThisWorkbook.Path & "\" & "BZ.mdb"
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & myPath & ";Jet OLEDB:Database Password=123"
SQL = "Select " & Join([b1:p1&""], ",") & " from 数据源 where 序号=" & Target & ""
Target.Offset(, 1).CopyFromRecordset cnn.Execute(SQL)
cnn.Close
Set cnn = Nothing
If Target.Cells.Count <> 1 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
If Target = "" Then Range("q" & Target.Row) = ""
If Not IsDate(Target.Offset(, 5)) Then Range("q" & Target.Row) = SQL = "Select 数量=数量+1 from 数据源 where 序号= & Target & "
End Sub
最后一句SQL语句执行后在excel中结果是FALSE请问该如何改写
http://pan.baidu.com/s/1kT3S975 展开
If Target.Count > 1 Then Exit Sub
If Target.Column > 1 Then Exit Sub
If Target = "" Then Exit Sub
Dim cnn As Object, SQL$
Dim myPath As String
Set cnn = CreateObject("ADODB.Connection")
myPath = ThisWorkbook.Path & "\" & "BZ.mdb"
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & myPath & ";Jet OLEDB:Database Password=123"
SQL = "Select " & Join([b1:p1&""], ",") & " from 数据源 where 序号=" & Target & ""
Target.Offset(, 1).CopyFromRecordset cnn.Execute(SQL)
cnn.Close
Set cnn = Nothing
If Target.Cells.Count <> 1 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
If Target = "" Then Range("q" & Target.Row) = ""
If Not IsDate(Target.Offset(, 5)) Then Range("q" & Target.Row) = SQL = "Select 数量=数量+1 from 数据源 where 序号= & Target & "
End Sub
最后一句SQL语句执行后在excel中结果是FALSE请问该如何改写
http://pan.baidu.com/s/1kT3S975 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询