We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Loop with textbox

Hi, I want to write a loop where the loop is a textbox in a form For i = Textbox1 to Textbox20 do something next i Problem: it cannot be a String or a textbox of an form or an object of an form ? it only works if i is an integer So i did the follwoing: Dim i as integer, e string For i = 1 To 20 e = "Textbox" & r Msgbox e ' => brings up Textbox1 Textbox2 Textbox3..... ' how can i convert this string to be seen as a textbox (or the values in it) ' this I want to to next: If e <> "value as String" then do something next i So it does this: if "Textbox1" (as string) <> "value as String" what I want to do : if "current value of textbox1 (as string)" <> "value as string" So how can I loop through all textboxes ?

1 Reply

TO Tommy November 12, 2002 06:37 AM

' I found the solution myself, for anybody who is interested here´s the code: ' The values of the textboxes are loaded into arrays Dim e As Variant, w As Variant e = Array(Me.Textbox1, Me.Textbox2, Me.Textbox3, Me.Textbox4, Me.Textbox5, Me.Textbox6) w = Array(Me.AnotherTextbox1, Me.AnotherTextbox2, Me.AnotherTextbox3, Me.AnotherTextbox4, Me.AnotherTextbox5, Me.AnotherTextbox6) ' Then the loop is done to check values in those boxes Dim r As Integer For r = 0 To 5 If e(r) <> "" And w(r) = "" Then do something End If Next r

Loader.
Live Chat Icon For mobile
Up arrow icon