Tony Miall
Active Member
- Joined
- Oct 16, 2007
- Messages
- 304
Hello everyone,
I have a user form that requires dates to be entered and found the following code which I applied to the text box to enforce the correct date format:
This works great and enters the date into to worksheet correctly.
Then when I call the user form if the cell already has a date value in it it repopulates the text box "InvoiceDate" with the date in the cell and it all looks fine. But when I run the macro again to enter the detail into the sheet the value entered into the cell shows as 0/01/1900 and I don't know why. I've tried various formats for the cell on the sheet itself but it doesn't work.
The relevant line of code I'm running off the form is:
I hope that's clear, any help appreciated as usual. Thanks
I have a user form that requires dates to be entered and found the following code which I applied to the text box to enforce the correct date format:
Code:
Private Sub InvoiceDate_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Mid(InvoiceDate.Value, 4, 2) > 12 Then
MsgBox "Invalid date, please re-enter using the correct format dd/mm/yyyy", vbCritical
InvoiceDate.Value = vbNullString
InvoiceDate.SetFocus
Exit Sub
End If
dDate = DateSerial(Year(Date), Month(Date), Day(Date))
InvoiceDate.Value = Format(InvoiceDate.Value, "dd/mm/yyyy")
dDate = InvoiceDate.Value
End Sub
This works great and enters the date into to worksheet correctly.
Then when I call the user form if the cell already has a date value in it it repopulates the text box "InvoiceDate" with the date in the cell and it all looks fine. But when I run the macro again to enter the detail into the sheet the value entered into the cell shows as 0/01/1900 and I don't know why. I've tried various formats for the cell on the sheet itself but it doesn't work.
The relevant line of code I'm running off the form is:
Code:
ActiveCell.Offset(0, 45).Range("A1").Select
ActiveCell.Value = dDate
I hope that's clear, any help appreciated as usual. Thanks