Private Sub Form_Load()
On Error GoTo ErrorHandler
Dim rst As Object
Dim rstTmp As Object
Dim strSQL As String
Dim currentID As String
CurrentDb.Execute "DELETE FROM TMP_发货_Detail"
If IsNull(Me.OpenArgs) Then
Me.DataEntry = True
End If
If Me.DataEntry Then
Exit Sub
End If
urrentID = Form_Frm_发货!Frm_发货_List_Child.Form.发货序号
strSQL = "select * from Tbl_发货 where 发货序号 ='" & currentID & "'"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
rst.MoveFirst
Me.发货序号 = currentID
Me.明细主号 = "F" & Mid([currentID], 4, 6)
………………
Me.备注 = rst!备注
rst.Close
strSQL = "select * from Tbl_发货_Detail where 发货序号 ='" & Me.发货序号 & "'"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
Set rstTmp = CurrentDb.OpenRecordset("TMP_发货_Detail")
Do Until rst.EOF
rstTmp.AddNew
rstTmp![发货序号] = rst![发货序号]
rstTmp![发货单号] = rst![发货单号]
rstTmp![订单明细] = rst![订单明细]
………………
rstTmp![金额] = rst![金额]
rstTmp![结算日期] = rst![结算日期]
rstTmp.Update
rst.MoveNext
Loop
rst.Close
rstTmp.Close
Me.Frm_发货_Edit_Detail_Child.Requery
ExitHere:
Set rst = Nothing
Set rstTmp = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbCritical
Resume ExitHere
End Sub
Private Sub Cmd保存_Click()
If Me.DataEntry Then
Call TJ
Me.Frm_发货_Edit_Detail_Child.Requery
Else
Call XG
DoCmd.Close acForm, Me.Name, acSaveNo
DoCmd.Restore
End If
End Sub
Public Sub TJ()
Dim rst As Object
Dim rstTmp As Object
Dim strSQL As String
Dim currentID As String
Dim currentID1 As String
strSQL = "select * from Tbl_发货_Detail WHERE [发货序号]='" & Me![发货序号] & "'"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
Set rstTmp = CurrentDb.OpenRecordset("TMP_发货_Detail")
Do Until rstTmp.EOF
rst.AddNew
rst![发货序号] = currentID
rst![订单明细] = rstTmp![订单明细]
…………
rst![数量] = rstTmp![数量]
rst![单价] = rstTmp![单价]
rst![金额] = Round(rstTmp![数量] * rstTmp![单价], 2)
rst.Update
rstTmp.MoveNext
Loop
rst.Close
rstTmp.Close
'将输入框清空
Dim ctrl As Control
For Each ctrl In Me.Form.Controls
If (TypeOf ctrl Is TextBox And InStr(1, ctrl.Name, "合计") = 0) Or TypeOf ctrl Is ComboBox Then
ctrl = Null
End If
Next ctrl
CurrentDb.Execute "DELETE FROM TMP_发货_Detail"
Form_Frm_发货.Frm_发货_List_Child.Form.Requery
MsgBox "新增的记录保存成功!", vbInformation, "提示"
ExitHere:
Set rst = Nothing
Set rstTmp = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbCritical
Resume ExitHere
End Sub
Public Sub XG()
Dim rst As Object
Dim rstTmp As Object
Dim strSQL As String
Dim currentID As String
strSQL = "select * from Tbl_发货 where 发货序号 ='" & Me.发货序号 & "'"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
rst.MoveFirst
rst.Edit
rst![审核] = Me.[审核]
…………
rst![备注] = Me![备注]
rst.Update
rst.Close
CurrentDb.Execute "Delete from Tbl_发货_Detail WHERE [发货序号]='" & Me![发货序号] & "'"
strSQL = "select * from Tbl_发货_Detail WHERE [发货序号]='" & Me![发货序号] & "'"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
Set rstTmp = CurrentDb.OpenRecordset("TMP_发货_Detail")
Do Until rstTmp.EOF
rst.AddNew
rst![发货序号] = Me![发货序号]
rst![订单明细] = rstTmp![订单明细]
………………
rst![数量] = rstTmp![数量]
rst![单价] = rstTmp![单价]
rst![金额] = Round(rstTmp![数量] * rstTmp![单价], 2)
rst.Update
rstTmp.MoveNext
Loop
rst.Close
rstTmp.Close
MsgBox "修改后的记录保存成功!", vbInformation, "提示"
ExitHere:
Set rst = Nothing
Set rstTmp = Nothing
Exit Sub
ErrorHandler:
MsgBox Err.Description, vbCritical
Resume ExitHere
End Sub作者: roych 时间: 2023-10-6 23:30
简单一点的做法是用dlookup处理,如果订单状态和完成日期都是唯一值的话。
需要注意的是,使用dlookup时一定确保有这个记录,否则会报错。
当然,你也可以再创建一个rst记录集,下拉订单明细时把订单条件传入,然后再赋值给控件。作者: yzc2011 时间: 2023-10-7 11:28
谢谢roych的回复,下面是单记录用于更改应收状态与完收日期,像发货这种多记录临时表,不知道怎么弄,就是有问题。能否帮忙做个实例,谢谢。
Private Sub JZ() '加载
Dim rst As Object
Dim strSQL As String
Dim currentID As String
currentID = Form_Frm_借贷收入_Edit.Form.对应号
strSQL = "select * from Tbl_利息应收 where 应收单号 ='" & currentID & "'"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
rst.MoveFirst
Me.应收状态 = rst!应收状态
Me.实收日期 = rst!实收日期
rst.Close
End Sub
Private Sub BC() '保存
Dim rst As Object
Dim strSQL As String
Dim currentID As String
currentID = Form_Frm_借贷收入_Edit.Form.对应号
strSQL = "select * from Tbl_利息应收 where 应收单号 ='" & currentID & "'"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
rst.MoveFirst
rst.Edit
rst!应收状态 = Me.应收状态
rst!实收日期 = Me.实收日期
rst.Update
rst.Close
End Sub 作者: roych 时间: 2023-10-7 20:26
其实就是加两列的问题。[attach]64682[/attach]
对于这个需求,其实我不是很理解的。以下是我的一些想法,供参考: