|
本帖最后由 djt 于 2009-9-1 09:08 编辑
能用类模块,应该可以自己改代码了
Private Sub 采购单号_DblClick(Cancel As Integer)
Dim Rs As New ADODB.Recordset
Dim Conn As New ADODB.Connection
Set Conn = CurrentProject.Connection
Dim Sql As String
Sql = "select * from 入库单明细 where 事务号='" & Me.事务号 & "' and 采购单行号=" & Me.采购单行号
Rs.Open Sql, Conn, adOpenKeyset, adLockReadOnly
If Rs.RecordCount >= 1 Then
MsgBox "该条记录已存在!", vbInformation + vbOKOnly, "重复提示"
Exit Sub
End If
Rs.Close
With Forms![入库单_录入].[入库单明细_子窗体].Form.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
.FindFirst "采购单ID='" & Me.采购单号 & "' and 采购单行号=" & Me.采购单行号
If .NoMatch = False Then
MsgBox "该条记录已存在!", vbInformation + vbOKOnly, "重复提示"
Exit Sub
End If
End If
End With
Sql = "select * from 入库单明细 where 事务号='" & Me.事务号 & "'"
Rs.Open Sql, Conn, adOpenDynamic, adLockOptimistic
If Not Rs.EOF Then
MsgBox "该条记录已存在!", vbInformation + vbOKOnly, "重复提示"
Exit Sub
End If
'Set Rs = Nothing
'Set Conn = Nothing
Forms![入库单_录入].SetFocus
DoCmd.GoToRecord , , acNewRec
If Forms![入库单_录入].[入库单明细_子窗体].Form.Recordset.RecordCount <= 2 Then
Forms![入库单_录入].[入库单明细_子窗体].Form.采购单ID = Me![采购单号]
Forms![入库单_录入].[入库单明细_子窗体].Form.入库日期 = Me![入库日期]
Forms![入库单_录入].[入库单明细_子窗体].Form.采购单行号 = Me![采购单行号]
Forms![入库单_录入].[入库单明细_子窗体].Form.入库数量 = Me![数量]
Forms![入库单_录入].[入库单明细_子窗体].Form.单价 = Me![采购单价]
Forms![入库单_录入].[入库单明细_子窗体].Form.总价 = Me![采购单价] * Me![数量]
Forms![入库单_录入].[入库单明细_子窗体].Form.事务号 = Me![事务号]
Else
Forms![入库单_录入].[入库单明细_子窗体].Form.采购单ID = Me![采购单号]
Forms![入库单_录入].[入库单明细_子窗体].Form.入库日期 = Me![入库日期]
Forms![入库单_录入].[入库单明细_子窗体].Form.采购单行号 = Me![采购单行号]
Forms![入库单_录入].[入库单明细_子窗体].Form.入库数量 = Me![数量]
Forms![入库单_录入].[入库单明细_子窗体].Form.单价 = Me![采购单价]
Forms![入库单_录入].[入库单明细_子窗体].Form.总价 = Me![采购单价] * Me![数量]
Forms![入库单_录入].[入库单明细_子窗体].Form.事务号 = Me![事务号]
End If
DoCmd.GoToRecord , , acNewRec
DoCmd.GoToRecord , , acLast
Dim rs1 As New ADODB.Recordset
rs1.Open "select * from 物料信息表 where 物料编号='" & Me.物料编号 & "'", Conn, adOpenKeyset, adLockReadOnly
If rs1.RecordCount >= 1 Then
Forms![入库单_录入].[入库单明细_子窗体].Form.物料编号 = rs1("物料编号")
Forms![入库单_录入].[入库单明细_子窗体].Form.物料名称 = rs1("物料名称")
Forms![入库单_录入].[入库单明细_子窗体].Form.类别 = rs1("类别")
Forms![入库单_录入].[入库单明细_子窗体].Form.上级ID = DLookup("[ID号]", "入库单明细", "[物料编号]='" & rs1("类别") & "'")
Forms![入库单_录入].[入库单明细_子窗体].Form.单位 = DLookup("[单位]", "物料信息表", "[物料编号]='" & rs1("物料编号") & "'")
End If
End Sub |
|