Matrix1000
asked on
How to stop Date/Time field from showing TIME
I have an access database with a Date/Time field.
When I send the Date/Time field to my lblBirthDate it shows the date thats in the field....but then it shows "12:00:00 AM".
So I want to strip off the 12:00:00 AM part so I used the code below...the problem is that when the form loads the lblBirthDate is empty and my Constructor code is cant run with no date, so the form won't load. I tried "If lblBirthDate = "" Then exit sub Else run code" but then the form loads but my constructor code never runs.
How can I load a record after Form_Load, and fill in lblBirthDate, but not have the time.
-----------CODE----------- -----CODE- ---------- -----CODE- ---------- --
'Add this code in the constructor of the form
public sub new
AddHandler label1.DataBindings("Text" ).Format, AddressOf DateToString
end sub
' Handles the Format event for the date
Protected Sub DateToString(ByVal sender As Object, ByVal e As ConvertEventArgs)
' You could use either of the following to convert to the proper date
' format:
'e.Value = CType(e.Value, DateTime).ToString("mm/dd/ yyyy")
e.Value = CType(e.Value, DateTime).ToShortDateStrin g
End Sub
When I send the Date/Time field to my lblBirthDate it shows the date thats in the field....but then it shows "12:00:00 AM".
So I want to strip off the 12:00:00 AM part so I used the code below...the problem is that when the form loads the lblBirthDate is empty and my Constructor code is cant run with no date, so the form won't load. I tried "If lblBirthDate = "" Then exit sub Else run code" but then the form loads but my constructor code never runs.
How can I load a record after Form_Load, and fill in lblBirthDate, but not have the time.
-----------CODE-----------
'Add this code in the constructor of the form
public sub new
AddHandler label1.DataBindings("Text"
end sub
' Handles the Format event for the date
Protected Sub DateToString(ByVal sender As Object, ByVal e As ConvertEventArgs)
' You could use either of the following to convert to the proper date
' format:
'e.Value = CType(e.Value, DateTime).ToString("mm/dd/
e.Value = CType(e.Value, DateTime).ToShortDateStrin
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
When I add it at the bottom of my DatabaseSearch() sub it underlines " e.Value" saying "Value not a member of System.EventArgs"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
-Baan
Thanks! but the form still wont load at first....I get an errror highlighting
"AddHandler label1.DataBindings("Text" ).Format, AddressOf DateToString"
Error: Additional information: Object reference not set to an instance of an object.
---------CONSTRUCTOR CODE AT THE TOP OF MY CODE-------------------
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'THIS AddHandler FORMATS MY DATE BOXES TO STRIP OFF THE TIME '12:00:00AM
AddHandler lblBirthDate.DataBindings( "Text").Fo rmat, AddressOf DateToString
End Sub
-------------------------- ---------- ---------- ---------- --
Is it because there is no date in the lblBirthDate yet while the form loads?
Thanks! but the form still wont load at first....I get an errror highlighting
"AddHandler label1.DataBindings("Text"
Error: Additional information: Object reference not set to an instance of an object.
---------CONSTRUCTOR CODE AT THE TOP OF MY CODE-------------------
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
'THIS AddHandler FORMATS MY DATE BOXES TO STRIP OFF THE TIME '12:00:00AM
AddHandler lblBirthDate.DataBindings(
End Sub
--------------------------
Is it because there is no date in the lblBirthDate yet while the form loads?
i had big probles with a date/time field, in the end i converted it text which solved all my problems
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER