Originally Posted by
RuralGuy
The "#" sign in the tool bar will create the code tags for you to put your code within.
Code:
' copy header record
Dim Con1 As New ADODB.Connection, Con2 As New ADODB.Connection
Set Con1 = CurrentProject.Connection
Set Con2 = CurrentProject.Connection
Dim rs1 As New ADODB.Recordset, rs2 As New ADODB.Recordset
rs1.Open "tblOEOrderHeader", Con1, adOpenDynamic, adLockPessimistic
rs2.Open "SELECT * FROM tblOEOrderHeader WHERE OrderHeaderID = " & OrderHeaderIDTxt, Con2, adOpenDynamic, adLockPessimistic
Dim F, FieldName As String
Dim HoldID As Long
rs1.AddNew
For Each F In rs2.Fields
FieldName = F.Name
If FieldName <> "OrderHeaderID" Then
If IsNull(rs1(FieldName)) And FieldName = "curr_cd" Then
rs1(FieldName) = ""
Else
rs1(FieldName).Value = rs2(FieldName).Value
End If
End If
Next
rs1("ord_no") = ""
rs1.Update
HoldID = rs1("OrderHeaderID")
rs1.Close: rs2.Close
Con1.Close: Con2.Close
Set rs1 = Nothing: Set rs2 = Nothing
Set Con1 = Nothing: Set Con2 = Nothing
' copy detail record(s)
Dim Con3 As New ADODB.Connection, Con4 As New ADODB.Connection
Set Con3 = CurrentProject.Connection
Set Con4 = CurrentProject.Connection
Dim rs3 As New ADODB.Recordset, rs4 As New ADODB.Recordset
Set Con3 = CurrentProject.Connection
Set Con4 = CurrentProject.Connection
rs3.Open "tblOEOrderDetail", Con3, adOpenDynamic, adLockPessimistic
rs4.Open "SELECT * FROM tblOEOrderDetail WHERE OrderHeaderID = " & OrderHeaderIDTxt, Con4, adOpenDynamic, adLockPessimistic
While Not rs4.EOF
rs3.AddNew
For Each F In rs4.Fields
If FieldName <> "OrderDetailID" Then
FieldName = F.Name
rs3(FieldName).Value = rs4(FieldName).Value
End If
Next
rs3.Update
rs4.MoveNext
Wend
rs3.Close: rs4.Close
Con3.Close: Con4.Close
Set rs3 = Nothing: Set rs4 = Nothing
Set Con3 = Nothing: Set Con4 = Nothing