Iteration through controls collection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an Access Project connected to an SQL Server database. I want to save
the values of the text boxes and combo boxes into a flat table. To do this, I
need to iterate through the controls collection. What is the syntax for doing
this just for these two types of control and for all of the controls on the
form?

many thanks,
Pete
 
Pete,

It would look something like:

Open "C:\SomeFile.txt" For Output As #1
For Each ctl in Me.Controls
If ctl.ControlType = acTextBox Or _
ctl.ControlType = acComboBox Then
Print #1, ctl.Name, ctl
End If
Next
Close #1

Or remove the If/Then/End If to include all controls. Note: this would
include command buttons, subfoms, activeX controls etc, and you'd
probably get errors.
Code is untested, but should work.

HTH,
Nikos
 
Some syntacticality I like:

select case ctl.controltype
case actextbox, accombobox ' by the way, no listboxes here?
print #1, etc
end select
 
Back
Top