PDA

View Full Version : [SOLVED] Default to current date in textbox



Joya
01-30-2017, 08:08 AM
Hi All,
I have a worksheet with a command button that opens an Excel form named frmMain.
On that form I have a frame named fraMain that has a textbox named txtDate. (The first field on the form)
I'm trying to get the current Date to populate the textbox automatically while also allowing the user to enter in a different date if needed.
This is what I've tried in the form VBA but no date shows up on the form load:
Private Sub frmMain_Initialize()
Me.txtDate.Text = Format(Now(), "MM/DD/YY")
End Sub

18184

Aflatoon
01-30-2017, 08:48 AM
The declaration is always this:

Private Sub Userform_Initialize()

You do not amend it to match the name of the form.

JKwan
01-30-2017, 08:49 AM
it should be this

Private Sub UserForm_Initialize()
Me.txtDate.Text = Format(Now(), "MM/DD/YY")
End Sub

Joya
01-30-2017, 09:18 AM
Thank you both for the quick replies it works perfectly now!