Darhl Thomason wrote:
I'm building a database application that has a number of date fields in it.
When I add the date/time picker control to my form and run it, if the field
is null in my db, then it shows the current date. How can I get this
control to be blank when the corresponding field in my db is blank?
There is no built in support in the control for null dates. Here's
what I did:
First I create two string to hold the date format. Note that the Not
Specified string includes an apostrophe (') at each end. 'Not
Specified'
Dim _userCustomFormat As String = "MM/dd/yyyy"
Dim _nullFormat As String = "'Not Specified'"
On the DateTimePicker control, set the format to Custom
Then in the code, check to see if the date is null (Nothing) and if so,
us the _nullFormat, otherwise use your desired date format:
If _dateVariable.HasValue Then
dtpDate.Value = _currentEmployee.AgreementDate.Value
dtpDate.CustomFormat = _userCustomFormat
Else
dtpDate.Value = DateTime.MinValue
dtpDate.CustomFormat = _nullFormat
End If
Hope this gives you some ideas.