should be easy! looping through textboxes

R

Rod

I want to be able to check all the textboxes in a form. I could not find a
way to loop through the text boxes directly and when I tried the following
code Access coughed on the .Value

any hints much appreciated.

many thanks

Rod

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Cntrl As Control

For Each Cntrl In Me.Controls
If Cntrl.ControlType = acTextBox Then
Debug.Print Cntrl.Value
End If
Next Cntrl

End Sub
 
R

Rick Brandt

Rod said:
I want to be able to check all the textboxes in a form. I could not find a
way to loop through the text boxes directly and when I tried the following
code Access coughed on the .Value

any hints much appreciated.

many thanks

Rod

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Cntrl As Control

For Each Cntrl In Me.Controls
If Cntrl.ControlType = acTextBox Then
Debug.Print Cntrl.Value
End If
Next Cntrl

End Sub

I copied and pasted your exact code into a test form and it ran fine for
me.
 
D

Dirk Goldgar

Rod said:
I want to be able to check all the textboxes in a form. I could not
find a way to loop through the text boxes directly and when I tried
the following code Access coughed on the .Value

any hints much appreciated.

many thanks

Rod

Private Sub Form_BeforeUpdate(Cancel As Integer)

Dim Cntrl As Control

For Each Cntrl In Me.Controls
If Cntrl.ControlType = acTextBox Then
Debug.Print Cntrl.Value
End If
Next Cntrl

End Sub

I don't see anything wrong with that code. What error was raised?
 
R

Rod

OK, sorry I was looking in the wrong direction, it was a mistake on my form
not in my code.

thanks all
 

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