CSDN博客

img zhangzs8896

PU1统计

发表于2004/9/19 12:28:00  455人阅读

分类: Office 开发

'--------------查询------------
Sub PU1TJ_write()
  Dim myCn As New ADODB.Connection
  Dim myrs As New ADODB.Recordset
  Dim strcon As String
 
  '-------------ADO数据库连接串-------------
  strcon = "PROVIDER=SQLOLEDB;SERVER=172.16.2.2;UID=sa;PWD=tpcims;DATABASE=Man" 'DL580-1
  On Error GoTo Error:
  myCn.ConnectionString = strcon
  myCn.CommandTimeout = 0
  myCn.Open
  myrs.ActiveConnection = myCn
 
 '---------------插入所查询的数据-------------
 m = 4
 n = 2
'----------------打开存储过程-------------
 mystr = "execute  PU1_TJ_ZHANGZS  '" + Trim(Txt_Date0.Text) + "','" + Trim(Txt_Date.Text) + "'"
 myrs.Open mystr
 
 Do While Not myrs.EOF
  Worksheets("TJ").Cells(m, n - 1) = m - 3
  If CStr(Trim(myrs!炉号)) <> "099999" Then
      Worksheets("TJ").Cells(m, n) = Trim(myrs!炉号)
  Else
      Worksheets("TJ").Cells(m, n) = ""
      Worksheets("TJ").Cells(m, n - 1) = ""
      'Worksheets("TJ").Cells(23, 3).Interior.PatternColorIndex = xlAutomatic
  End If
  Worksheets("TJ").Cells(m, n + 1) = CStr(Trim(myrs!入库日期)) + "  " + CStr(Trim(myrs!入库时间))
  Worksheets("TJ").Cells(m, n + 2) = Trim(myrs!钢种)
  Worksheets("TJ").Cells(m, n + 3) = Trim(myrs!定尺长度)
  Worksheets("TJ").Cells(m, n + 4) = Trim(myrs!铸坯外径)
  Worksheets("TJ").Cells(m, n + 5) = Trim(myrs!支数)
  Worksheets("TJ").Cells(m, n + 6) = Trim(myrs!重量)
  Worksheets("TJ").Cells(m, n + 7) = Trim(myrs!库位)
 
  If Left(CStr(Trim(myrs!炉号)), 1) = "0" Then
  Worksheets("TJ").Cells(m, n + 8) = Trim(myrs!电炉时间)
  Worksheets("TJ").Cells(m, n + 9) = Trim(myrs!重废)
  Worksheets("TJ").Cells(m, n + 10) = Trim(myrs!统废)
  Worksheets("TJ").Cells(m, n + 11) = Trim(myrs!铁水)
  Worksheets("TJ").Cells(m, n + 12) = Trim(myrs!生铁)
  Worksheets("TJ").Cells(m, n + 13) = Trim(myrs!海绵铁)
  Worksheets("TJ").Cells(m, n + 14) = Trim(myrs!进口废钢)
  Else
  Worksheets("TJ").Cells(m, n + 8) = ""
  Worksheets("TJ").Cells(m, n + 9) = ""
  Worksheets("TJ").Cells(m, n + 10) = ""
  Worksheets("TJ").Cells(m, n + 11) = ""
  Worksheets("TJ").Cells(m, n + 12) = ""
  Worksheets("TJ").Cells(m, n + 13) = ""
  Worksheets("TJ").Cells(m, n + 14) = ""
  End If
 myrs.MoveNext
 m = m + 1
 Loop
 myrs.Close
 myCn.Close
 
Exit Sub
 
 '----------出现错误执行以下代码--------------
Error:
  MsgBox Err.Description, vbOKOnly, "Error Message"
End Sub
'-------------清空记录的函数--------------
Sub Clear()
For i = 4 To 104
  For j = 1 To 16
   Worksheets("TJ").Cells(i, j) = ""
  Next j
Next i
End Sub

'-----统计计算-----------暂时没有用到!
Sub js()
  For i = 4 To 43
  Worksheets("TJ").Cells(44, 5) = Worksheets("TJ").Cells(44, 5) + Worksheets("TJ").Cells(i, 5)
  Next i
End Sub

'--------------查询记录-----------------
Private Sub Check_Click()
 Call Clear
 Call PU1TJ_write
 Columns("B:Q").AutoFit
End Sub
'-------------清空记录--------------
Private Sub Clear_Row_Click()
 Call Clear
 Columns("B:Q").AutoFit
End Sub

0 0

相关博文

我的热门文章

img
取 消
img