Sub 生成()
Set conn = CreateObject("adodb.connection")
conn.Open "driver=sql server;server=pz01;database=IQCSIP;uid=iqc;pwd=Iqcsip2020"
If conn.State = 1 Then
Dim str_MAXNO As String
Dim str_MAXGL As String
str_MAXNO = "select MAX(NO) from SBGL where 计测器名称 = '" & ActiveSheet.Cells(5, 1) & " '"
ActiveSheet.Cells(3, 8).CopyFromRecordset conn.Execute(str_MAXNO)
If ActiveSheet.Cells(3, 8) = "" Then
MsgBox "数据库内无此计测器记录,请在A3处输入HXX-XXX", 32, "提示"
End If
’前面没问题 出问题的是下面这两行 我需要他导出1个结果 数据库里面确实有3个符合条件的结果
str_MAXGL = "select 管理NO from SBGL where 计测器名称 = '" & ActiveSheet.Cells(5, 1) & " 'and NO = '" & ActiveSheet.Cells(3, 8) & " ' "
ActiveSheet.Cells(3, 1).CopyFromRecordset conn.Execute(str_MAXGL)
End If
conn.Close
Set conn = Nothing
MsgBox "程序已执行完毕", 32, "提示"
End Sub