Loop through all text/combo boxes on a form?

B

BlueWolverine

Hello,
MS ACCESS 2003 on XP PRO.

I would like to loop through every field on my form. I want to do something
like this:

For Each object on Forms!my_Form

if object = text box or object = combination box then
Array_Value(lcv,0) = object.value
arra_value(lcv,1) = object.name
lcv=lcv+1
next object


How do I actually execute this? my biggest concern is on writing the for
loop and the if statement.

Thanks
 
D

Dirk Goldgar

BlueWolverine said:
Hello,
MS ACCESS 2003 on XP PRO.

I would like to loop through every field on my form. I want to do
something
like this:

For Each object on Forms!my_Form

if object = text box or object = combination box then
Array_Value(lcv,0) = object.value
arra_value(lcv,1) = object.name
lcv=lcv+1
next object


How do I actually execute this? my biggest concern is on writing the for
loop and the if statement.


Try this:

Dim ctl As Access.Control

For Each ctl In Forms!My_Form.Controls

If ctl.ControlType = acTextBox _
Or ctl.ControlType = acComboBox _
Then
Array_Value(lcv,0) = ctl.Value
Array_Value(lcv,1) = ctl.Name
lcv=lcv+1
End If

Next ctl

If this code is running on the form in question, you can simplify the
reference to the form:

For Each ctl In Me.Controls
 

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