Hi folks,
I have inherited an evaluation form and have a couple of improvements I want to do to it.
There are 2 date fields on the form, Session Date and DOB. There is no formatting control on this so I want to force the date entered to be formatted correctly and throw a message box up if someone tries to use a different format.
Found this code but I need to tweak it so that it's pulling date from the form rather than a cell location:
In the VBA the boxes are called: DOBTextBox and SessionsBox
I want to ensure that the users enter the dates as dd/mm/yyyy in the Form but also when the macro copies the information from the form into a sheet that it retains the correct formatting.
Issue arises when someone enters 03/06/2008 as DOB but when it copies to the sheet the formatting switches to 06/03/2008.
Any guidance would be much appreciated.
Lee
I have inherited an evaluation form and have a couple of improvements I want to do to it.
There are 2 date fields on the form, Session Date and DOB. There is no formatting control on this so I want to force the date entered to be formatted correctly and throw a message box up if someone tries to use a different format.
Found this code but I need to tweak it so that it's pulling date from the form rather than a cell location:
Code:
Dim dDate As DatePrivate Sub CommandButton1_Click()
Sheet1.Range("G1").Value = dDate
End Sub
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Mid(TextBox1.Value, 4, 2) > 12 Then
MsgBox "Invalid date format, please re-enter as dd/mm/yyyy", vbCritical
TextBox1.Value = vbNullString
TextBox1.SetFocus
Exit Sub
End If
dDate = DateSerial(Year(Date), Month(Date), Day(Date))
TextBox1.Value = Format(TextBox1.Value, "dd/mm/yyyy")
dDate = TextBox1.Value
End Sub
In the VBA the boxes are called: DOBTextBox and SessionsBox
I want to ensure that the users enter the dates as dd/mm/yyyy in the Form but also when the macro copies the information from the form into a sheet that it retains the correct formatting.
Issue arises when someone enters 03/06/2008 as DOB but when it copies to the sheet the formatting switches to 06/03/2008.
Any guidance would be much appreciated.
Lee