frmXXX_EDIT窗体记录源默认是空的。
保存代码如下:
Private Sub btnSave_Click()
On Error GoTo ErrorHandler
If Not CheckRequired(Me) Then Exit Sub
If Not CheckTextLength(Me) Then Exit Sub
If Not CheckRequired(Me.sfrDetail) Then Exit Sub
Dim cnn: Set cnn = GetADOConnection()
cnn.BeginTrans
Dim blnTransBegin As Boolean: blnTransBegin = True
If Nz(Me![图纸编号]) = "" Then Me![图纸编号] = GetAutoNumber("图纸编号")
Dim strSQL: strSQL = "SELECT * FROM [tblPDM] WHERE [图纸编号]=" & SQLText(Me![图纸编号])
Dim rst: Set rst = ADO.OpenRecordset(strSQL, adLockOptimistic, cnn)
If rst.EOF Then rst.AddNew
UpdateRecord Me, rst
'你的自定义代码
rst.Update
rst.Close
cnn.Execute "DELETE FROM [tblpdmgx] WHERE [图纸编号]=" & SQLText(Me![图纸编号])
strSQL = "SELECT * FROM [tblpdmgx] WHERE [图纸编号]=" & SQLText(Me![图纸编号])
Set rst = ADO.OpenRecordset(strSQL, adLockOptimistic, cnn)
Dim rstTmp: Set rstTmp = CurrentDb.OpenRecordset("TMP_tblpdmgx")
Do Until rstTmp.EOF
rst.AddNew
UpdateRecord rstTmp, rst
rst![更新编号] = GetAutoNumber("更新编号")
rst![图纸编号] = Me![图纸编号]
rst.Update
rstTmp.MoveNext
Loop
rst.Close
rstTmp.Close
cnn.CommitTrans
blnTransBegin = False
RequeryDataObject gsfrList
MsgBoxEx LoadString("Saved Successfully."), vbInformation
If Me.DataEntry Then
Me.InitData
Else
DoCmd.Close acForm, Me.Name, acSaveNo
End If
ExitHere:
Set rst = Nothing
Set cnn = Nothing
Set rstTmp = Nothing
Exit Sub
ErrorHandler:
If blnTransBegin Then
cnn.RollbackTrans
blnTransBegin = False
End If
RDPErrorHandler Me.Name & ": Sub btnSave_Click()"
Resume ExitHere
End Sub