|
表1(plan),表2(end_plan)
我通过表2里面设定的参数来查询表1
参数是WO_NUMBER ;排产日期这两个参数进行查询
例如附件中的例子 输入WO_NUMBER:21840091 值查询后
出现的结果值里面的WO_Number的值是文本格式
但是表1(plan)中的WO_Number的值是数字格式
我想得到的结果是数字格式,即使把表二字段改为数字格式,修改后表1的相关字段WO_NUMBER也被修改为文本格式了
因此请老师修改一下里面的代码!给解决一下,谢谢
我知道里面字段声明为文本格式了,但是不知如何修改里面的代码
ITEM ITEM_DESC WO_Qty ACT追踪 WO_Number 排产日期
VA001-507-30 G2012*PED* 3 xx 21840091 2/19/2020
Sub ChaXunData()
Application.ScreenUpdating = False
Dim Bvalue$, Dvalue$ '为文本格式了,但是修改为数值型后面的代码报错
With Sheet9
Bvalue = .Range("B1").Value
Dvalue = .Range("D1").Value
If Bvalue = "" And Dvalue = "" Then
Else
Dim iRow&
Dim cnn As New ADODB.Connection, rs As New ADODB.Recordset, SQL$
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
'注意下面的语句的取值范围,如有增加需要修改取值范围
If Bvalue <> "" And Dvalue <> "" Then
SQL = "Select ITEM, ITEM_DESC,WO_QTY,ACT追踪,WO_Number,排产日期 From [PLAN$A:Z] Where WO_Number='" & Bvalue & "' And 排产日期=#" & Dvalue & "#"
ElseIf Bvalue <> "" And Dvalue = "" Then
SQL = "Select ITEM,ITEM_DESC,WO_QTY,ACT追踪,WO_Number,排产日期 From [PLAN$A:Z] Where WO_Number='" & Bvalue & "'"
ElseIf Dvalue <> "" And Bvalue = "" Then
SQL = "Select ITEM,ITEM_DESC,WO_QTY,ACT追踪,WO_Number,排产日期 From [PLAN$A:Z] Where 排产日期=#" & Dvalue & "#"
End If
Set rs = cnn.Execute(SQL)
iRow = .Range("A" & .Rows.Count).End(3).Row
If iRow > 2 Then .Range("A3:E" & iRow).ClearContents
.Range("A3").CopyFromRecordset rs
cnn.Close
Set cnn = Nothing
Set rs = Nothing
End If
End With
Application.ScreenUpdating = True
End Sub
Sub modifiedData()
Application.ScreenUpdating = False
Dim iRow&, i&, arr()
With Sheet9
iRow = .Range("A" & .Rows.Count).End(3).Row
If iRow > 2 Then
arr = .Range("A3:F" & iRow).Value
Dim cnn As New ADODB.Connection, SQL$
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
For i = 1 To UBound(arr)
SQL = "Update [PLAN$A:Z] set [ITEM]='" & arr(i, 1) & "',[ITEM_DESC]='" & arr(i, 2) & "',[WO_Qty]='" & arr(i, 3) & "',[ACT追踪]='" & arr(i, 4) & "',[WO_Number]='" & arr(i, 5) & "',[排产日期]=#" & arr(i, 6) & "# where [WO_NUMBER]='" & arr(i, 5) & "'"
cnn.Execute SQL
Next i
MsgBox "数据修改完毕!", vbOKOnly, "提示"
End If
cnn.Close
Set cnn = Nothing
End With
Application.ScreenUpdating = True
End Sub
|
|