views:

7

answers:

1

Forgive me about the title, I have no idea what this is called.

I have a MS Access database set up, with a Period field that has either values 1, 2, 3, 4 or 5. I retrieve these values using a database connection and I would like to reference a particular control based on what period was grabbed from the database.

Here's example code, pseudo of course.

TextBox(dr(3)).Text = dr(0)

dr(3) contains the period, and dr(0) contains the content I would like to put into the text box. I have these text boxes on my form: TextBox1, TextBox2, TextBox3, TextBox4 and TextBox5.

So if dr(3) contained 2 then I would want to reference TextBox2.

I hope I've made myself clear, any help would be greatly appreciated, thanks. :)

A: 

I think you need something like this:

CType(Me.Controls("Textbox" & dr(3)), TextBox).text = dr(0)

The key point is that you can use the Controls collection of the container of the textboxes to reference the textbox you want

rip