|
本帖最后由 wangxk0807 于 2016-8-26 20:40 编辑
原程序没有查询功能很不方便,下面是我复制别的老师的代码 加入查询,点击查询时没有显示该单号的数据
Sub 查询()
Dim HM, cel As Range
If Range("K3").Value = "" Then MsgBox "请输入需要查询的单据号码": Exit Sub
ActiveSheet.Unprotect
Application.ScreenUpdating = False
Range("K4").Value = ""
HM = Range("K3").Value
For Each cel In Sheet2.Range("D2:D" & Sheet2.[E65536].End(xlUp).Row)
If cel.Value = HM Then
If cel.Offset(0, 1).Value <> "" Then
Range("b3") = " 入 库 单"
End If
Range("D4") = cel.Offset(0, -2).Value
Range("E4") = cel.Offset(0, -1).Value
Range("K4") = cel.Offset(0, -3).Value
End If
Next
Set Conn = CreateObject("Adodb.Connection")
Conn.Open "provider=microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source=" & ThisWorkbook.FullName
If Range("b3") = "入 库 单" Then
Sql = "select 代码,分类,货品名称,规格型号,单位,数量,单价 from [入库数据$] where 单号='" & [K3] & "'"
[c7].CopyFromRecordset Conn.Execute(Sql)
Sql = "select 备注 from [入库数据$] where 单号='" & [K3] & "'"
[K7].CopyFromRecordset Conn.Execute(Sql)
Selection.Locked = False
End If
Conn.Close
Set Conn = Nothing
Application.ScreenUpdating = True
ActiveSheet.Protect
End Sub
结果查询不显示数据,不知道错在哪里,谢谢老师赐教指正
|
-
这是保存的入库数据
-
这是需要查询的入库单
|