Form Display Issue

Craw

New Member
Joined
Jul 27, 2011
Messages
32
Greetings,
I am trying to write a code that will automatically display the current date in a form when that form is opened. The following is the code I have so far and I have to click in the textbox and press a key for the date to be displayed which is not what I want.

Code:
Private Sub TextBox1_initialize()
'Date
 TextBox1 = Date
 End Sub

Any suggestions?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi, the question is ambiguous so I will give you two solutions based on two problems.

1) The date the form is opened.
Code:
Private Sub UserForm_Initialize()
    TextBox1.Text = Date
End Sub

2) The date is constantly being updated
Code:
Private Sub UserForm_Initialize()
 
Time_Loop:
    DoEvents
    TextBox1.Text = Date
    GoTo Time_Loop
End Sub
 
Upvote 0
My apologies let me try and clarify. I just want a textbox in the corner of a form. Whenever a user opens the form the textbox will display the current date. In which case I believe that a loop function is necessary. I have tried the #2 code you recommended but to no avail. The code you suggested is supposed to go into the form module?

Code:
Private Sub Toolbox1_Initialize()
 
Time_Loop:
DoEvents
TextBox1.Text = Date
GoTo Time_Loop
End Sub
 
Upvote 0
What kind of error are you getting with the code provided?

Please note that you must already have a textbox in the corner of your userform named "TextBox1"

and also, please note that Private Sub Userform_Initialize()
is found by going into the userform module
and on the top right quadrant of the editor, there are two long dropdown box where you can select the object in the first box and event of it in the second box.

so in the first box, you want Userform and in the second box, you want to select Initialize

then your editor will show Private Sub Userform_Initialize() End Sub
automatically and you should put the code in that.
 
Upvote 0
I did just that however I still have click on the textbox when I open the form in order for the current date to be displayed.
 
Upvote 0
Can you show me the code you have used?

meanwhile, you can try this:
Rich (BB code):
Private Sub Toolbox1_Initialize()
 
Timer_Loop:
DoEvents
Me.TextBox1.Text = Date
GoTo Timer_Loop
End Sub
 
Upvote 0
There is no ToolBox1_Initialize event.

What is ToolBox anyway?
 
Upvote 0
I have both of the following codes in the module for the form in question (Toolbox1). Seeing as it wasn't working as a textbox I am now trying it as a label.

Code:
Private Sub Label1_Click()
    Label1.caption = Format(Now, "dd/mm/yyyy")
End Sub
 
Private Sub Toolbox1_Initialize()
 
Timer_Loop:
DoEvents
Me.Label1.Text = Date
GoTo Timer_Loop
 
End Sub
 
Upvote 0
Oops I meant
Rich (BB code):
Private Sub Userform_Initialize()
 
Timer_Loop:
DoEvents
Me.TextBox1.Text = Date
GoTo Timer_Loop
End Sub

Thanks for pointing it out, norie.
 
Upvote 0
Craw, there is no Toolbox1 event.
Is that the name of your userform?
It still does not matter so you should just use Userform_Initialize()
 
Upvote 0

Forum statistics

Threads
1,224,509
Messages
6,179,192
Members
452,893
Latest member
denay

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top