'form globals
Dim rsDoc As New ADODB.Recordset 'Bad form to do "New" here
Dim rsPay As New ADODB.Recordset 'Bad form to do "New" here
dim DocIDSave as long
Private Sub Form_Open(Cancel As Integer)
rsDoc.Open "Documents", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adLockOptimistic
rsPay.Open "Payments", CurrentProject.Connection, adOpenKeyset, adLockOptimistic, adLockOptimistic
End Sub
Private Sub gen_Click()
'validate record as a whole
addHeader
'loop thru either memory buffer or file buffer
'for/while NOT eof or at end of buffer
addLine
end sub
private sub addHeaders()'After button click & validations
rsDoc.AddNew
'the DocID primary Key is AutoNumber
rsDoc!PayeeID = selPayID 'from a form's control
'More fields are set like above
rsDoc.Update 'Post your changes
DocIDSave = rsDoc!DocID 'For linking line items
End Sub
Private Sub addLine() 'After button click & validations
'PayID primary key is autonumber too
rsPay.AddNew
rsPay!DocID = DocIDSave 'link to the header
'set fields
rsPay.Update
End Sub