Link to home
Start Free TrialLog in
Avatar of richardlh
richardlh

asked on

How should I make a label visible over a textbox when condition met?

I have a form where I put a label with a message over a textbox. The idea is to have the label become visible and block out the textbox when a certain condition is met. Otherwise, the label is not visible and the record’s information in the textbox is visible.

The textbox is on a subform displaying data for records selected in the main form. The subroutine is working when I use a message box, but I like the idea of the label showing on top of the textbox so they are always together no matter where the user moves the window to and also so the user does not have to click a button to get rid of the MsgBox. The label is on top of the textbox just to alert the user that there are no records in the subform recordsource for the primary recordsource in the main form.

I placed the label on top of the textbox and made it invisible (format "on-top") and then turn on the visibility with a sub procedure. However, when the procedure runs it appears that the textbox has priority to be visible. I tried making the textbox invisible, but I get an error that the procedure cannot make the control invisible when it has the focus.

Any suggestions?
Avatar of jjafferr
jjafferr
Flag of Oman image

Hi richardlh,

make the Textbox invisible and the Lable visible,
me.Textbox.visible=false
me.Lable.visible=True

Hope this helps

Jaffer
richardlh,
didn't see the last part,

try

me.Lable.setfocus
me.Textbox.visible=false
me.Lable.visible=True

jaffer
I think the best idea is to use conditional formatting then you don't need to use code at all.
When the condition is fulfilled have it that the text box is disabled & another textbox shows up (on the main form) with the message that you require.
tbsgadi
Conditional formating does not allow for visible/invisible

Yes you can use Conditional formating if you have a white background for example, so make your default text color as white, and when your condition is met, change the Font color to something else.

jaffer
That's exactly what I meant for the other textbox,but I wrote to disable the the original textbox (which it does do)
ASKER CERTIFIED SOLUTION
Avatar of Mighty_Silly
Mighty_Silly
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are right Mighty_Silly
you cannot set focus to a Label,
thus the focus should be set to the next Textbox

jaffer
Avatar of richardlh
richardlh

ASKER

Ah yes, use an unbound textbox with a [= "Text goes here statement"] then shift the focus to the one made visible and the other textbox, make it invisible. I will try that and post the results. Thanks for the quick response. Back in a little while.

Have a great day :-), Richard
Mighty Silly,

Converting the label to a textbox, seting the focus to it, and controling the visible property did the trick. Thanks a bunch and I hope to help others with their questions with Access and VBA as I gain more knowledge and experience.

Regards, Richard

You're very welcome Richard!  Glad I could help.

Sites like this have truly widen my knowledge in various topics, and I have no doubt I'll continue to learn from other Experts from this site.

By keeping an open mind I continue to learn various ways to achieve desired result, thus enabling me to select the "most suitable" solution for a particular situation.

Thanks for the Points award.

-Silly-