Unbound form Iterate a recordset with loop changing the textbox name from text1 to text2 to display information vba code

Posted on 2006-05-17
Last Modified: 2012-06-27
I am using Access 2003.
I have an unbound form with a text boxes say text1 , text2, etc to text10   I need to iterate the recordset and change the recipient of the record each time from text1 to text2.  So I need build the name from text on the first loop to  text1 and so on. I can do this the long way but would like a neater way.
The reason I am using unbound is that there is a lot of data from many sources on the form and I would end up with lots of listboxes or sub -forms.  Thanks
Question by:Mike_Leggett
    1 Comment
    LVL 11

    Accepted Solution

    Um...not sure if this is what you mean but:

    For i = 0 to MyRecordset.Fields.Count -1

    Me.Controls("text" & CStr(i +1)).Value = MyRecordset.Fields(i).Value

    Next i

    This writes the field values to each text box, incrementing as they go. If this is correct but populates the text boxes in the wrong order then you are better to name you textboxes appropriately to match the Fields.Name property and use that instead. Otherwise please could you restate your requirement.


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    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…
    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

    732 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

    22 Experts available now in Live!

    Get 1:1 Help Now