MS Access and OnGotFocus

Jmas46
10-15-2004, 12:33 PM
Is there a way that I can reference all textboxes on a form so that when they have focus the backcolor changes to a different color.

P.S. Keep in mind that I know how to do this for each text box in event GotFocus/LostFocus. However, this is a pain in the neck if you have to do this for every textbox on a form. Is there a generic way to reference all the textboxes?


Thanks. :confused:

MKoslof
10-15-2004, 06:11 PM
Just to verify, are you working with VB controls, or native VBA controls? Have you considered using a control array?

Jmas46
10-15-2004, 09:21 PM
Just to verify, are you working with VB controls, or native VBA controls? Have you considered using a control array?

I am working with native vba controls. How would I go about using a control array?

MKoslof
10-16-2004, 08:59 AM
Well, Access VBA does not support control arrays. You have a few options if you want Control Array type functionality.

My first suggestion would be to work within a set of naming conventions. Meaning you give each control a common name and increment. Then you can iterate through ALL text boxes on your form within the form_load event by using one loop and set whatever properties you need, something like:



'I have 11 controls
For i=0 To 10
'set them all to visible, etc
Me("txtBox" & i).Visible = True
Next i

Jmas46
10-18-2004, 09:37 AM
Thanks For your help.
I like how the for next loop statements work.
The only problem I am having is getting these statements to work at the form level only when a textbox has focus. When a textbox has focus I want the backcolor to be yellow, when it does not have focus I want a white backcolor.

Timbo
10-18-2004, 10:13 AM
Although you can't make a true control array in MS Office, you can emulate them using class arrays. The attached example illustrates how to implement the concept in Access - in this case for CommandButtons, however adapting the idea for TextBoxes is quite simple :)

Jmas46
10-18-2004, 11:34 AM
Thanks Timbo. It will take a little while to convert the code for use with text boxes. Simple for you but harder for me (novice). That is what I am looking for except for the fact that if they are text fields and you TAB to one, the backround will not change color because the mouse pointer triggers the events, (Is that correct?)

Timbo
10-18-2004, 11:51 AM
Well I used the MouseMove for that example, but I imagine you would need the 'GotFocus' event. Take a look in the Class Module, click in the existing event, then use the procedure box at the top-right of the VB Editor to select the event you need.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum