Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change field's caption, based on time

Status
Not open for further replies.

pdtit

Technical User
Nov 4, 2001
206
BE
Hello,

I have totals-field on my form, which shows the sum of all other fields on my form.

The totals-field caption is eg. "Balance".

On my form, I also have a field "Time", which shows the current time when the form is opened.

Can anyone guide me what code and on which field to put it, to have the caption changed to "Openingsbalance" or "Closingsbalance", based on the time.

Regards,

Peter
 
First, you can't change the Caption property of the text box, because text boxes don't have a Caption property. The Caption property is actually on the Label control that's attached to the text box. Unfortunately, Label controls aren't available to your VBA code. (Well, actually, I think there's a way, but it's obscure. There's a better solution. Read on.)

Open your form in Design View, and right click on the Label control. From the shortcut menu, choose Change to..., and then select Text Box. This changes your label control to a text box control, which you can then access from code. Now, you don't want this text box to be updatable by the user, so change its properties to make it disabled, locked, flat, and with a transparent background. After you do that, it will look just like a label again, except that it will say "Unbound" instead of "Balance".

Now you need to write code to set the text box to the chosen caption. It looks like this:
Code:
    If Time() < #16:30# Then
        Label1 = &quot;Openingsbalance&quot;
    Else
        Label1 = &quot;Closingsbalance&quot;
    End If
Substitute the name of your label-turned-text box for &quot;Label1&quot;, and substitute the time of day you want it to change for 16:30 (4:30pm in military time).

Do you only need to do this once, when the form is opened? Or is the form left open all day, and you want it to change automatically at, say, 4:30pm? If you only need it once, just put the above code in the Form_Open procedure. If you want it to change dynamically, put it in the Form_Timer procedure, and set the form's TimerInterval property to the number of milliseconds you want to wait between checks for the time of day. To check every minute, for instance, set TimerInterval to 60000. Rick Sprague
 

if Format(Now, &quot;hh:hh:mm:&quot;) > &quot;12;00:00) Then
[tab]me.labelX.Caption = &quot;This is Afternoon&quot;
Else
[tab]me.labelX.Caption = &quot;This is Morning&quot;
End If


MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Michael, Rick,

As I didn't have that much time to investigate this all for the moment, I tried Michael's code, and it works great.

I changed the &quot;Now&quot; in to Me.time (my field is named time) and when leaving the field, my caption is changed as wanted.

Thank you very much.

Regards,

PdtIt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top