How to get hold of data from subforms

  • Thread starter Thread starter Dominique Heyler
  • Start date Start date
D

Dominique Heyler

I have a form displaying data from a customer table. It includes a subform
for phone numbers (stored in a related table). I've figured how to get hold
of the data in text fields, but I'm having a real hard time finding out how
to access data from the subform. My code looks something like this:



Sub GetField()

Dim cField As Control

For Each cField In Me.Controls

'Text

If cFelt.ControlType = 109 Then

debug.print (cField.Value, "")

'Subform

ElseIf cField.ControlType = 112 Then

???

End If

Next

End Sub



Any idea how this can be done?



:-) Dominique
 
What are you aiming to do:
a) to loop through all the controls of the current record record in the
subform, or
b) to loop through all the records in the subform.

You code is doing (a).
For (b), loop through the RecordsetClone, starting with a MoveFirst, until
EOF. This kind of thing:

Dim rs As DAO.Recordset
Dim fld As DAO.Field

Set rs = Me.[NameOfYourSubformHere].Form.RecordsetClone
If rs.RecordCount > 0 Then
rs.MoveFirst
Do While Not rs.EOF
For Each fld in rs.Fields
Debug.Print fld.Name, fld.Value
Next
Debug.Print
rs.MoveNext
Loop
End If

Set fld = Nothing
Set rs = Nothing
 
Back
Top