I don't think I know how to do that. Can you explain how?
If I understood your question correctly:
What is the SQL of the subform?
Copy that and add the criteria that links the sub form to the main form.
Steps:......
If the SQL of the subform record source is
Code:
SELECT SubFormID_PK, MainFormID_FK, Field1, Field2, lngPO_Key, AnotherField_FK
FROM tblTable1
to change to VBA, use
Code:
ssql = "SELECT SubFormID_PK, MainFormID_FK, Field1, Field2, lngPO_Key, AnotherField_FK
ssql = ssql & " FROM tblTable1
Next add the criteria to link the main form to the sub form records (PK to FK)
Code:
ssql = "SELECT SubFormID_PK, MainFormID_FK, Field1, Field2, lngPO_Key, AnotherField_FK
ssql = ssql & " FROM tblTable1
ssql = ssql & " WHERE MainFormID_FK = " & Me.MainFormID_PK
Now the records should match the sub form records.
So getting just the [PO_Key], change the SQL to
Code:
ssql = "SELECT DISTINCT lngPO_Key
ssql = ssql & " FROM tblTable1
ssql = ssql & " WHERE MainFormID_FK = " & Me.MainFormID_PK
Opening a record set on the above SQL would result in a domain of unique lngPO_Key values.
Code:
Sub SomeCode()
dim d as dao.database
dim r as dao.recordset
dim sSQL as string
set d = currentdb
ssql = "SELECT DISTINCT lngPO_Key
ssql = ssql & " FROM sfSource"
ssql = ssql & " WHERE MainFormID_FK = " & Me.MainFormID_PK
set r = d.openrecordset(ssql)
If not (r.bof and r.eof) then
r.MoveFirst
Do WHILE NOT r.EOF
' create append query here
r.MoveNext
Loop
End If
r.Close
Set r = Nothing
Set d = Nothing
End Sub