Iteration through controls collection

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
 
N

Nikos Yannacopoulos

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
 
B

Bas Cost Budde

Some syntacticality I like:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top