|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> "$A$2" Then Exit Sub
If Target = "" Then Exit Sub
Dim cnn As Object, rs As Object, SQL$
If Len([a2]) >= 4 Then
SQL = "Select 物品编码,物品名称,规格型号 from 编码库 where 物品编码 like '%" & [a2] & "%'"
Else
MsgBox "请输入物品编码的4位数以上!", vbInformation, "系统提示"
Exit Sub
End If
Set cnn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cnn.Open "Provider=Microsoft.Jet.Oledb.4.0;data Source=" & ThisWorkbook.Path & "\编码库.mdb"
rs.Open SQL, cnn, 1, 3
If rs.RecordCount Then
ActiveSheet.UsedRange.Offset(2).ClearContents
[a3].CopyFromRecordset rs
Else
MsgBox "没有查到!"
End If
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub |
|