|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
各位大神:
新手学数据库,做了个小程序,数据库能连接成功,并且读取数据,但是读取完成后提示:未指定错误,请帮忙看看哪里有问题
Private Sub Worksheet_Change(ByVal Target As Range)
Dim mydata As String, mytable As String, SQL As String
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim i As Integer
mydata = ThisWorkbook.Path & "\技术参数.mdb"
mytable = "参数"
Set cnn = New ADODB.Connection
With cnn
.Provider = "microsoft.jet.oledb.4.0"
.Open mydata
End With
SQL = "select * from " & mytable & " where 梯型 ='" & Range("e4").Value & "' and 载重 ='" & Range("h4").Value & "'"
Set rs = cnn.Execute(SQL)
If rs.EOF Then
MsgBox "无数据记录"
Else
Range("l4").Value = rs.Fields("轿厢尺寸")
End If
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
主要就是读取一个与单元格数据匹配的数据库参数。在.Open mydata这一条提示未指定错误。但是数据库的数据又是读取成功了,求大神指点
|
|