Selecting a Text Box based on a Variable

barno_xvi

Registered User.
Local time
Today, 01:27
Joined
Aug 19, 2006
Messages
21
Right, I'm not sure if this can be done, but I've had a fair stab at it myself and am rather stuck :confused:

I have a combo box with dates in. I have stored the number of the day in a variable and wish to use that variable to select a specific textbox.

Hope that makes sense...

Basically, here's an example:

If the value of the combo box was say "01/01/01"
and in the variable would therefore be 1,
I want to select text box 1.

Whereas if I selected "02/01/01" from the combo box,
I want text box 2 to be selected :o

Any ideas?! Thanks in advance.
 
See if you can find a way to use this syntax:
Me.Controls("txtBox" & Day(DateValue(Me.cboName)))

You may need to play with it a bit and it requires that your TextBoxes are carefully named.
 
Omg!

Thanks so much!

That was the perfect solution! I tried doing something like that quite a few times but am not very familiar with the Me! element of programming. I'm getting there, lol but thanks very much for your help, that was great.

Barnz
 
Saving?!

The thing that I wanted it to do was to change the backcolor of the text box to show that it was "occupied". It turns red and it works great, except for the fact that it does not stay there. As soon as I change the view from say design to form or I just reopen the form etc, it is back to normal?!

Any ideas how I can save the back colour? I have tried just using the simple "DoCmd.Save" command but this hasn't worked. Thanks.
 
In what event did you put your code and what is the actual code you used?
 
Code

It was just inside a Command Button:

Private Sub Select_Click()
Me.Controls("R1D" & Me.StartDate.Caption).BackColor = "255"
End Sub

The TextBoxes are named "R1D...." plus an integer of the day. The StartDate being just a label containing the integer.
 
Last edited:
Can you put similar code in the Current event of the form and the AfterUpdate event of the ComboBox that picks dates?
 
Right ummm ok. I'm not sure if it worked or not. It's worked for two boxes but after that it doesn't :confused: not sure how that's happened?! but yeah.I'll keep fiddling but thanks for that. I'll get back to you later.
 
Use Conditional formatting

Rural Guy is helping a lot in this forum. Keep it up. As he will do help in the after update event of the combo box, I hope I need not. I think conditional formatting the required controls will also help you.
 
Oooo yeah. Thanks for that. Completely forgot about Conditional Formatting as I've only ever really used it in Excel! That actually helped a lot. Thanks.
 

Users who are viewing this thread

Back
Top Bottom