Automatically populate a date in a form

gmazza76

Well-known Member
Joined
Mar 19, 2011
Messages
771
Office Version
  1. 365
Platform
  1. Windows
Good Morning,

I have been trying to find a way of automatically populating the date in a textbox in a form.

Is this possible as all i can find is a formula for excel =()Today and when i use this it doesnt work.

Many Thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Where would i put this.

ie in the code for the textbox as per below

Private Sub txtdate_Change()

End Sub

Cheers
 
Upvote 0
May be like this

Code:
Private Sub UserForm_Initialize()
Dim TODAY
TODAY = Format(Now, "mm/dd/yyyy")
Me.TextBox1.Value = TODAY
End Sub
 
Upvote 0
Sorry about this but i am being really thick.

I have the following " Private Sub Userform_Initialize()" as follows.
Where would i be best putting this in the code

Code:
Private Sub Userform_Initialize()
 
    With CmbCSM
        .AddItem "Andrew Mellor"
        .AddItem "Ashley Longman"
        .AddItem "Christine Whitty"
    
    End With
      
    With cmbAdvocate
        .Enabled = False
    End With
           
    With ComboBox1
        .AddItem "Dual"
        .AddItem "Electric"
        .AddItem "Gas"
    End With
     
    With ComboBox2
        .AddItem "Yes"
        .AddItem "No"
    End With
       
    With ComboBox5
        .AddItem "Yes"
        .AddItem "No"
        .AddItem "N/A"
    End With
       
        
    With ComboBox3
       
        .AddItem "Billing (EC)"
        .AddItem "Change of Supplier-Acq (EC)"
        .AddItem "Change of Supplier-Other (EC)"
        .AddItem "Change of Supplier-Wthdwl (EC)"
        .AddItem "Debt (EC)"
        .AddItem "Homemove (EC)"
        .AddItem "Metering (EC)"
        .AddItem "Payment Issues (EC)"
        .AddItem "Policy (EC)"
    End With
    
End Sub

Cheers
 
Upvote 0
Here

Code:
Private Sub Userform_Initialize()
Dim today as Date
 
today = Format(Now, "mm/dd/yyyy")
Me.TextBox1.Value = today

    With CmbCSM
        .AddItem "Andrew Mellor"
        .AddItem "Ashley Longman"
        .AddItem "Christine Whitty"
    
    End With
      
    With cmbAdvocate
        .Enabled = False
    End With
           
    With ComboBox1
        .AddItem "Dual"
        .AddItem "Electric"
        .AddItem "Gas"
    End With
     
    With ComboBox2
        .AddItem "Yes"
        .AddItem "No"
    End With
       
    With ComboBox5
        .AddItem "Yes"
        .AddItem "No"
        .AddItem "N/A"
    End With
       
        
    With ComboBox3
       
        .AddItem "Billing (EC)"
        .AddItem "Change of Supplier-Acq (EC)"
        .AddItem "Change of Supplier-Other (EC)"
        .AddItem "Change of Supplier-Wthdwl (EC)"
        .AddItem "Debt (EC)"
        .AddItem "Homemove (EC)"
        .AddItem "Metering (EC)"
        .AddItem "Payment Issues (EC)"
        .AddItem "Policy (EC)"
    End With
    
End Sub
 
Upvote 0
:):)

Many Thanks

That works brilliantly.
Is there anyway i can protect the textbox so it cannot be changed?

Cheers Again
 
Upvote 0
Try this

Code:
Private Sub Userform_Initialize()
Dim today as Date

today = Format(Now, "mm/dd/yyyy")
Me.TextBox1.Value = today
Me.TextBox1.Locked = True

    With CmbCSM
        .AddItem "Andrew Mellor"
        .AddItem "Ashley Longman"
        .AddItem "Christine Whitty"
    
    End With
      
    With cmbAdvocate
        .Enabled = False
    End With
           
    With ComboBox1
        .AddItem "Dual"
        .AddItem "Electric"
        .AddItem "Gas"
    End With
     
    With ComboBox2
        .AddItem "Yes"
        .AddItem "No"
    End With
       
    With ComboBox5
        .AddItem "Yes"
        .AddItem "No"
        .AddItem "N/A"
    End With
       
        
    With ComboBox3
       
        .AddItem "Billing (EC)"
        .AddItem "Change of Supplier-Acq (EC)"
        .AddItem "Change of Supplier-Other (EC)"
        .AddItem "Change of Supplier-Wthdwl (EC)"
        .AddItem "Debt (EC)"
        .AddItem "Homemove (EC)"
        .AddItem "Metering (EC)"
        .AddItem "Payment Issues (EC)"
        .AddItem "Policy (EC)"
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,555
Members
452,928
Latest member
101blockchains

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