should be easy! looping through textboxes

  • Thread starter Thread starter Rod
  • Start date Start date
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
 
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.
 
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?
 
OK, sorry I was looking in the wrong direction, it was a mistake on my form
not in my code.

thanks all
 
Back
Top