|
COOL 看看这断代码.
Dim con As ADODB.Connection '声名数据库对象
Dim rec As Recordset '声名记录集对象
Dim rec1 As Recordset '声名记录集对象
Dim rec2 As Recordset '声名记录集对象
Dim rec3 As Recordset '声名记录集对象
Dim rec4 As Recordset '声名记录集对象
Dim rec5 As Recordset '声名记录集对象
Dim rec6 As Recordset '声名记录集对象
Dim rec7 As Recordset '声名记录集对象
Dim rec8 As Recordset '声名记录集对象
Dim rec9 As Recordset '声名记录集对象
Dim searchkey, searchkey1, searchkey2, repair As String
Dim rec3count, reccount, fate As Integer
Dim strsql, strsql1, strsql2, strsql3, strsql4, strsql5, strsql6, strsql7, strsql8, strsql9 As String
Dim fie As ADODB.Field
Dim msg, title, response
Set con = New Connection '数据库对象实例化例 dim con as new adodb.connection
Set con = CurrentProject.Connection '指定数据库为当前数据库
Set rec = New Recordset '记录集对象实例化 dim rec as new recordset
rec.ActiveConnection = con
con.BeginTrans
'判定是否重复把条码表中的数据增加到搜索明细表中
'读取条码表中的第一条流水号
strsql7 = "select 流水号 from 条码"
Set rec7 = New Recordset
rec7.Open strsql7, con, 3, 3, 1
'搜查第一条流水号是否在搜索明细表中
strsql8 = "select 流水号 from 搜索明细表 where 流水号='" & rec7.Fields(0).value & "'"
Set rec8 = New Recordset
rec8.Open strsql8, con, 3, 3, 1
If rec8.Fields(0).value = "" Then
'打开条码表记录集(搜索是我们出货的产品)
strsql = "select 条码.*,出货明细表.* from 条码,出货明细表 where ([条码].[流水号] between 出货明细表.[起始流水号] and 出货明细表.[结束流水号])"
rec.Open strsql, con, 3, 3, 1
While Not rec.EOF
'输出产品名称
searchkey2 = rec.Fields(4).value
strsql4 = "select * from 产品表 where 产品编号=" & searchkey2 & ""
Set rec2 = New Recordset
rec2.Open strsql4, con, 3, 3, 1
'输出出货单中的出货日期
searchkey = rec.Fields(2).value '获取出货明细表中的出货单编号赋给searcheky变量
strsql2 = "select * from 出货单 where 出货单编号=" & searchkey & "" '搜索出货编号相对应的出货日期
Set rec3 = New Recordset
rec3.Open strsql2, con, 3, 3, 1
'输出客户表中的客户名称
searchkey1 = rec3.Fields(1).value '获取出货单中的客户名称赋给searcheky变量
strsql3 = "select * from 客户表 where 客户编号=" & searchkey1 & ""
Set rec4 = New Recordset
rec4.Open strsql3, con, 3, 3, 1
If (Date - rec3.Fields(2).value) <= 425 Then
repair = "保修期"
Else
repair = "保修期已过"
End If
'将返修品插入到搜索明细表中
strsql5 = "insert into 搜索明细表(流水号,出货单编号,客户名称,产品名称,出货日期,保修状况,处理结果) values ('" & rec.Fields(0).value & "'," & rec.Fields(2).value & ",'" & rec4.Fields(1).value & "','" & rec2.Fields(1).value & "','" & rec3.Fields(2).value & "','" & repair & "','龙腾产品')"
Set rec5 = New Recordset
rec5.Open strsql5, con, 3, 3, 1
rec.MoveNext
Wend
'搜索非龙腾出货产品
Set rec1 = New Recordset
strsql1 = "select 条码.* from 条码 where [条码].[流水号] not in (select [条码].[流水号] from 条码,出货明细表 where [条码].[流水号] between 出货明细表.[起始流水号] and 出货明细表.[结束流水号])"
rec1.Open strsql1, con, 3, 3, 1
While Not rec1.EOF
'将非龙腾产品插入搜索明细表中
strsql6 = "insert into 搜索明细表(流水号,处理结果) values ('" & rec1.Fields(0).value & "', '非龙腾产品')"
Set rec6 = New Recordset
rec6.Open strsql6, con, 3, 3, 1
Debug.Print vbCr
rec1.MoveNext
Wend
msg = "条码表中的流水号处理完成,请查看记录!"
title = "数据处理操作窗口"
response = MsgBox(msg, vbInFORMation, title)
Else
msg = "请查看记录,你已处理过该笔返修品了!"
title = "数据处理操作窗口"
response = MsgBox(msg, vbExclamation, title)
Exit Sub
End If
con.CommitTrans
rec.Close
con.Close
Set con = Nothing |
|