Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Help   Contact   Merch   Join   Order   Logon   Forums   
 
Back to Access Forum    Comments List
Upload Images | @Reply | Bookmark | Link | Email | Next Unseen |
Looping through form controls
Alex Hedley 
           
15 years ago
Hi Scott,

I've sort of got it working but it's not efficient, think I've got an extra loop I don't need, always struggle with the nested loops!

I've had to change a couple of things too.
Firstly I've named the textboxes 0 1 2 3 not 01 02 03 as I would need an extra if statement checking if the value was less than 10 add a leading zero.
Another presumption is you run the code with a button once the 2 values are populated into certain textboxes.

So I've got a textbox called txtTime [tasktimestart] and txtHours [subtotalUHU].
I guess you will set those with the query when you open the form from another form.

Then I have a couple of textboxes hr0 -> hr3.

I've added a button on the form - btnFill
I've manually changed txtTime & txtHours then pressed the button and it fills in only the textboxes within the loop.

Now here is the code

Private Sub btnFill_Click()
    MsgBox "a"
    Dim ctl As Control
    
    Dim time As Integer
    time = txtTime
    Dim hours As Integer
    hours = txtHours
    
    For i = time To (time + hours)
        For Each ctl In Me.Controls
            If ctl.ControlType = acTextBox Then
                    MsgBox ctl.Name
                    If ctl.Name = "hr" & i Then
                       ctl.Value = 1
                    End If
            End If
        Next ctl
    Next i
End Sub


Now you have a loop from the time it starts to the time it starts plus the number of hours it takes.

Is that what you were after?

Is there a better way Rick?


Reply from Richard Rost:

Nope... you got it. You guys are too good.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
 
What's This?

 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 10/16/2026 1:41:52 AM. PLT: 0s