Solved

Loop through elements of a continuous form

Posted on 2002-03-19
5
1,141 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

735 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