Solved

Loop through elements of a continuous form

Posted on 2002-03-19
5
1,071 Views
Last Modified: 2012-08-14
Hi,

Hope this doesn't sound too confusing...

How do I loop through a specific textbox on a form that is repeated any number of times? (continuous versus single page).

What I need to be able to do is check the value of each textbox.

Thanks in advance,

David.
0
Comment
Question by:DSE
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:Paurths
ID: 6879630
hi DSE,

here is an example that will 'visit' each textbox on a form, and display its data in a messagebox

Private Sub cmdLoopTXT_Click()
Dim ctrl As Control

    For Each ctrl In Me.Controls
        If TypeOf ctrl Is TextBox Then
            MsgBox ctrl.Value
            'do your action here
        End If
    Next ctrl
End Sub


cheers
Ricky
0
 

Author Comment

by:DSE
ID: 6879672
Hi Ricky,

I have tried to modify the code you wrote but I seem to be having some trouble implementing it. The repeated form has well over 100 records displayed but the code appears to only loop through 3 of them.

Can you help?

Thanks,

David.

This is the code I used:
------------------------

Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf ctrl Is TextBox Then
   If SBSP = Null Then
      MsgBox "ok"
    End If
Else
End If

Next ctrl
0
 

Author Comment

by:DSE
ID: 6879674
sorry...SBSP is the name of the textbox that I want to specifically check the value of.
0
 
LVL 12

Accepted Solution

by:
Paurths earned 50 total points
ID: 6879685
my mistake,

i missed the 'continuous form' part...

is SBSP also the name of the field in your table?

cmdLoopTXT_Click()
Dim rst As Recordset

    Set rst = Me.RecordsetClone
   
    rst.MoveFirst
    While Not rst.EOF
        MsgBox rst!SBSP
    rst.MoveNext
    Wend
       
    rst.Close
    Set rst = Nothing
end sub
0
 

Author Comment

by:DSE
ID: 6879702
Thanks a lot Paurths,

It worked great first time without changing a thing!

Thanks again,

David.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now