查询时,出现 实时错误-2147467259的提示
用如下代码查询数据,在“If rs.RecordCount = 0 Then”上出现如图所示错误,请问代码哪里有问题?Dim sql
Dim rs As New ADODB.Recordset, cn As New ADODB.Connection
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
If rs.State = adStateOpen Then rs.Close
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Jet OLEDB:Database Password=;Persist Security Info=False;"
sql = "SELECT Tb_yongliang.hetonghao, Tb_yongliang.chanpinhao, Tb_yongliang.yuanliaochanpinhao, Tb_yongliang.yuanliaosehao, Tb_yongliang.aigoufangshi, Format(int(Tb_yongliang.yingyongliang),'#,##0.00') as yingyongliang, format(cInt(IIf(IsNull(Tb_huansuanlv.huansuanlv),Tb_yongliang.yingyongliang,Tb_yongliang.yingyongliang/Tb_huansuanlv.huansuanlv)),'#,##0.00') AS caigoushuliang FROM Tb_yongliang LEFT JOIN Tb_huansuanlv ON Tb_yongliang.yuanliaochanpinhao = Tb_huansuanlv.chanpinhao where TB_yongliang.hetonghao='" & & "'"
rs.Open sql, cn, 1, 1
Set Me.DataGrid1.DataSource = Nothing
Set Me.DataGrid1.DataSource = rs
'设定DataGrid1的列宽
DataGrid1.Columns(0).Width = 1000
DataGrid1.Columns(1).Width = 1500
DataGrid1.Columns(2).Width = 1500
DataGrid1.Columns(3).Width = 800
DataGrid1.Columns(4).Width = 800
DataGrid1.Columns(5).Width = 2000
DataGrid1.Columns(6).Width = 2000
DataGrid1.Refresh
If rs.RecordCount = 0 Then
MsgBox "没有找到符合条件的数据!", vbExclamation, "提示"
Exit Sub
End If