|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
打开以前2007版office 编写的文件。发现读取ComboBox里面的赋值总是错误,debug后,错误停留在下面代码的语句 .Range("yyyy") = 0
现在用的office 2010, 请问专家怎么修改代码才不会出现debug提示. 请看下面的代码
Private Sub CommandButton4_Click() 'Horizontal
Dim Sql$, Conn
With Sheets("DatedWells")
'******** define the year when the wells drilled********
If Me.ComboBox2.Value = "Unlimited" Then
.Range("yyyy") = 0
Else
.Range("yyyy") = Me.ComboBox2.Value
End If
'****************************************************
Range("A4:L2000").ClearContents
Set Conn = CreateObject("adodb.connection")
Conn.Open "provider=microsoft.jet.oledb.4.0;extended properties='excel 8.0;imex=1';data source=" & ThisWorkbook.FullName
If .Range("yyyy") <> 0 Then
Sql = "Select Rig_Nr,Well_Name,Mv_Date,Spud_Date,TD_Date,Rlsd_Date,Current_Depth,AFE_Nr,Block,Acc_Cost,Classification,Type from [rawdata$]where Type='Horizontal'And year(" & .Range("Search_Dates") & ")=" & .Range("yyyy") & " order by Rlsd_Date"
Else
Sql = "Select Rig_Nr,Well_Name,Mv_Date,Spud_Date,TD_Date,Rlsd_Date,Current_Depth,AFE_Nr,Block,Acc_Cost,Classification,Type from [rawdata$]where Type='Horizontal' order by Rlsd_Date"
End If
Range("a4").CopyFromRecordset Conn.Execute(Sql)
Conn.Close
Set Conn = Nothing
End With
End Sub |
|