|
楼主 |
发表于 2020-3-30 10:06
|
显示全部楼层
魂断蓝桥 发表于 2020-3-30 09:39
On Error GoTo 100
cnn.Open "Provider=microsoft.jet.oledb.4.0;Data Source=" & App.Path & "\test. ...
Option Explicit
Dim m As Boolean
Sub 开始()
Dim bt$, CNN, RS, SQL$, TJ$, i%, NewTime
bt = " [WRN#],班次,录入员,生产线,品种,取样时间,吸碘值,吸油值,[325#水洗],[200#水洗],[100#水洗],[35#水洗],[10#粒子],最大颗粒强度,平均颗粒强度,最小颗粒强度,水分,倾注密度,罐号,温度"
Sheet1.Unprotect Password:="123"
If m = True Then m = False: Exit Sub
For i = 2 To 4 Step 2
TJ = TJ & Cells(3, i - 1) & "='" & Cells(3, i) & "' and "
Next
TJ = Left(TJ, Len(TJ) - 4)
NewTime = Now + TimeValue("00:01:00")
Set CNN = CreateObject("ADODB.Connection")
Set RS = CreateObject("adodb.Recordset")
CNN.Open "provider=microsoft.ace.oledb.12.0;data source=" & ThisWorkbook.Path & "\数据库.accdb" & ";Jet OLEDB:Database Password=123578951;"
SQL = "select top " & [f3] & bt & " from 生产命令单 where " & TJ & " order by id desc"
SQL = "select * from (" & SQL & ") order by [WRN#]"
[a17:t23] = ""
Range("A17").CopyFromRecordset CNN.Execute(SQL)
[a17:a22].NumberFormatLocal = "yyyy/m/d hh:mm:ss"
[f17:f22].NumberFormatLocal = "hh:mm:ss"
SQL = "select top " & [j3] & bt & " from 生产命令单 where " & TJ & " order by id desc"
SQL = "select * from (" & SQL & ") order by [WRN#]"
[a27:t77] = ""
Range("A27").CopyFromRecordset CNN.Execute(SQL)
[f27:f77].NumberFormatLocal = "hh:mm:ss"
Set RS = Nothing
Set CNN = Nothing
Application.OnTime NewTime, "开始"
Sheet1.Protect Password:="123"
End Sub
Sub 结束()
m = True
End Sub
|
|