Userform textbox date input

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Hi,

I would like that when i open the userform the dat would automatically be shown in textbox 1

I thought the below code was correct but upon opening the form textbox 1 is still empty.


Code:
ThisWorkbook.Worksheets("POSTAGE").Cells(LastRow + 1, 1).Value = TextBox1.Text = Format(Now(), "MM/DD/YY")
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
'Load your form
Load frmManagerTool

'Set the default value
frmUserform.txtInputBox.Value = Today()

user the names of your form and inputbox
 
Upvote 0
If like this then i see not defined message

Code:
Private Sub CommandButton1_Click()UserForm1.Show.txtInputBox1.Value = Today()


End Sub
 
Upvote 0
This works on the userform main sheet.


Code:
Private Sub UserForm_Initialize()TextBox1.Value = Now
TextBox1 = Format(TextBox1.Value, "dd/mm/yyyy")
End Sub
 
Upvote 0
here is some code I'm using to setup the default value of 2 text box as 1 when the userform is loaded.

Sub Show_UserForm()


Load frmManagerTool

frmManagerTool.txtPriorite.Value = 1
frmManagerTool.txtQuantite.Value = 1

frmManagerTool.Show




End Sub

then update with the name of your userform (mine is frmMAnagerTool ) and textbox (mine is txtPriority and Quantity)
 
Upvote 0
Can you advise on the code that i am using.

My form was called UserForm & the code that was in use is shown below,this entered the dat in TextBox 1 no problem.

Code:
Private Sub UserForm1_Initialize()TextBox1.Value = Now
TextBox1 = Format(TextBox1.Value, "dd/mm/yyyy")
TextBox2.SetFocus

End Sub

I have now changed the name of the form to Postage Transfer Form.
So i then edited the code to reflex in this as shown below.

Code:
Private Sub PostageTransferSheet_Initialize()TextBox1.Value = Now
TextBox1 = Format(TextBox1.Value, "dd/mm/yyyy")
TextBox2.SetFocus


End Sub

When the form is now open there is no date shown in Text Box 1 ?
 
Upvote 0
try with that code:
Private Sub PostageTransferSheet_Initialize()

Me.TextBox1.Value = Format(Now,"DD/MM/YYYY")

End Sub

works for me.
 
Upvote 0
On vb Editor double click on the display of the userform

on the top left corner in vb editor choose from the dropdown list Userform and then form the top left corner choose Initialized.

the name might be " Private SUb Userform_Initialized

then try the code above. You have to make sure to use the name setup in the userform you can see them in the properties tab
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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