By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,075 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

date/time field in access shows nonexistant time in databound textbox.

P: n/a
I have a textbox that is databound to a table in an access database.
The field only contains month/day/year but my databound textbox is
also showing a time. Is there any way to prevent it from doing this?

---
Kyote
Aug 16 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
You can at least use format events

http://www.vb-tips.com/DataBindingEvents.aspx

Cor

"Kyote" <ky********@nospamhotmail.comschreef in bericht
news:k7********************************@4ax.com...
>I have a textbox that is databound to a table in an access database.
The field only contains month/day/year but my databound textbox is
also showing a time. Is there any way to prevent it from doing this?

---
Kyote
Aug 16 '07 #2

P: n/a
Kyote wrote:
I have a textbox that is databound to a table in an access database.
The field only contains month/day/year
No, a Date/Time field actually always contains a time component, but the
time may be set to 00:00:00.

The value is read into the .NET type DateTime, which also always
contains a time component.
but my databound textbox is
also showing a time. Is there any way to prevent it from doing this?
Specify the FormatString in the Binding object.

--
Göran Andersson
_____
http://www.guffa.com
Aug 16 '07 #3

P: n/a
Cor,

Here is your example changed to use FormatString and NullValue properties:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3. Private ds As New DataSet
  4.  
  5. Private Sub Form1_Load(ByVal sender As Object, ByVal e As
  6. System.EventArgs) Handles Me.Load
  7.  
  8. Dim dt As New DataTable
  9. ds.Tables.Add(dt)
  10. dt.Columns.Add("DateField", GetType(System.DateTime))
  11. dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
  12. dt.LoadDataRow(New Object() {Nothing}, True)
  13. dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)
  14.  
  15. Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField", True)
  16. Mybinding.FormatString = "MM/dd/yyyy"
  17. Mybinding.NullValue = "No date"
  18. TextBox1.DataBindings.Add(Mybinding)
  19.  
  20. End Sub
  21.  
  22. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
  23. System.EventArgs) Handles Button1.Click
  24.  
  25. 'forward
  26. Me.BindingContext(ds.Tables(0)).Position += 1
  27.  
  28. End Sub
  29.  
  30. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
  31. System.EventArgs) Handles Button2.Click
  32.  
  33. 'backward
  34. Me.BindingContext(ds.Tables(0)).Position -= 1
  35.  
  36. End Sub
  37. End Class
  38.  
Kerry Moorman
"Cor Ligthert[MVP]" wrote:
You can at least use format events

http://www.vb-tips.com/DataBindingEvents.aspx

Cor

"Kyote" <ky********@nospamhotmail.comschreef in bericht
news:k7********************************@4ax.com...
I have a textbox that is databound to a table in an access database.
The field only contains month/day/year but my databound textbox is
also showing a time. Is there any way to prevent it from doing this?

---
Kyote

Aug 17 '07 #4

P: n/a
Kerry,

Thanks

I will see if I can implement it, a problem with checking for nulls is often
that it makes the sample more difficult to read. It is about to tell how it
can be done.

"Learning to fish not giving the fish".

I started this were I needed it for dates before 1753 and than raised those
by 3000

Maybe I make 2 samples from it.

Cor


"Kerry Moorman" <Ke**********@discussions.microsoft.comschreef in bericht
news:45**********************************@microsof t.com...
Cor,

Here is your example changed to use FormatString and NullValue properties:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.    Private ds As New DataSet
  3.    Private Sub Form1_Load(ByVal sender As Object, ByVal e As
  4. System.EventArgs) Handles Me.Load
  5.        Dim dt As New DataTable
  6.        ds.Tables.Add(dt)
  7.        dt.Columns.Add("DateField", GetType(System.DateTime))
  8.        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
  9.        dt.LoadDataRow(New Object() {Nothing}, True)
  10.        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)
  11.        Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField",
  12. True)
  13.        Mybinding.FormatString = "MM/dd/yyyy"
  14.        Mybinding.NullValue = "No date"
  15.        TextBox1.DataBindings.Add(Mybinding)
  16.    End Sub
  17.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
  18. System.EventArgs) Handles Button1.Click
  19.        'forward
  20.        Me.BindingContext(ds.Tables(0)).Position += 1
  21.    End Sub
  22.    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
  23. System.EventArgs) Handles Button2.Click
  24.        'backward
  25.        Me.BindingContext(ds.Tables(0)).Position -= 1
  26.    End Sub
  27. End Class
  28.  

Kerry Moorman
"Cor Ligthert[MVP]" wrote:
>You can at least use format events

http://www.vb-tips.com/DataBindingEvents.aspx

Cor

"Kyote" <ky********@nospamhotmail.comschreef in bericht
news:k7********************************@4ax.com.. .
>I have a textbox that is databound to a table in an access database.
The field only contains month/day/year but my databound textbox is
also showing a time. Is there any way to prevent it from doing this?

---
Kyote

Aug 17 '07 #5

P: n/a
On Thu, 16 Aug 2007 20:21:50 +0200, "Cor Ligthert[MVP]"
<no************@planet.nlwrote:
>You can at least use format events

http://www.vb-tips.com/DataBindingEvents.aspx
Thank you for the response Ken, and the help. I've done as it asked
and I'm currently playing around with it to try to understand all
that's happening. It does appear this would solve my problem. LOL
Looks like I'll be busy for a while trying to understand this.

---
Kyote
Aug 17 '07 #6

P: n/a
On Thu, 16 Aug 2007 21:00:36 +0200, Göran Andersson <gu***@guffa.com>
wrote:
>Kyote wrote:
>I have a textbox that is databound to a table in an access database.
The field only contains month/day/year

No, a Date/Time field actually always contains a time component, but the
time may be set to 00:00:00.

The value is read into the .NET type DateTime, which also always
contains a time component.
>but my databound textbox is
also showing a time. Is there any way to prevent it from doing this?

Specify the FormatString in the Binding object.
Thank you also for your response. I think your pretty much telling me
to do what Ken's example is showing me. With my limited understanding
of databinding and similar concepts this is going to take me quite a
while to understand, I have can understand it in a basic way even now.
So I have strong hopes of figuring out what all is happening to such a
degree that I can then make use of it for my app and any future app as
well.

Again, thank you for the help.
---
Kyote
Aug 17 '07 #7

P: n/a
Kerry,

The new Tip is here

http://www.vb-tips.com/DataBindingFormatFields

Cor

"Kerry Moorman" <Ke**********@discussions.microsoft.comschreef in bericht
news:45**********************************@microsof t.com...
Cor,

Here is your example changed to use FormatString and NullValue properties:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.    Private ds As New DataSet
  3.    Private Sub Form1_Load(ByVal sender As Object, ByVal e As
  4. System.EventArgs) Handles Me.Load
  5.        Dim dt As New DataTable
  6.        ds.Tables.Add(dt)
  7.        dt.Columns.Add("DateField", GetType(System.DateTime))
  8.        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
  9.        dt.LoadDataRow(New Object() {Nothing}, True)
  10.        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)
  11.        Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField",
  12. True)
  13.        Mybinding.FormatString = "MM/dd/yyyy"
  14.        Mybinding.NullValue = "No date"
  15.        TextBox1.DataBindings.Add(Mybinding)
  16.    End Sub
  17.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
  18. System.EventArgs) Handles Button1.Click
  19.        'forward
  20.        Me.BindingContext(ds.Tables(0)).Position += 1
  21.    End Sub
  22.    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
  23. System.EventArgs) Handles Button2.Click
  24.        'backward
  25.        Me.BindingContext(ds.Tables(0)).Position -= 1
  26.    End Sub
  27. End Class
  28.  

Kerry Moorman
"Cor Ligthert[MVP]" wrote:
>You can at least use format events

http://www.vb-tips.com/DataBindingEvents.aspx

Cor

"Kyote" <ky********@nospamhotmail.comschreef in bericht
news:k7********************************@4ax.com.. .
>I have a textbox that is databound to a table in an access database.
The field only contains month/day/year but my databound textbox is
also showing a time. Is there any way to prevent it from doing this?

---
Kyote

Aug 19 '07 #8

P: n/a
It does not show up in the link, we will have a look at the problem.

By hand it is there.

Cor

"Cor Ligthert[MVP]" <no************@planet.nlschreef in bericht
news:ui**************@TK2MSFTNGP04.phx.gbl...
Kerry,

The new Tip is here

http://www.vb-tips.com/DataBindingFormatFields

Cor

"Kerry Moorman" <Ke**********@discussions.microsoft.comschreef in
bericht news:45**********************************@microsof t.com...
>Cor,

Here is your example changed to use FormatString and NullValue
properties:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.    Private ds As New DataSet
  3.    Private Sub Form1_Load(ByVal sender As Object, ByVal e As
  4. System.EventArgs) Handles Me.Load
  5.        Dim dt As New DataTable
  6.        ds.Tables.Add(dt)
  7.        dt.Columns.Add("DateField", GetType(System.DateTime))
  8.        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
  9.        dt.LoadDataRow(New Object() {Nothing}, True)
  10.        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)
  11.        Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField",
  12. True)
  13.        Mybinding.FormatString = "MM/dd/yyyy"
  14.        Mybinding.NullValue = "No date"
  15.        TextBox1.DataBindings.Add(Mybinding)
  16.    End Sub
  17.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
  18. System.EventArgs) Handles Button1.Click
  19.        'forward
  20.        Me.BindingContext(ds.Tables(0)).Position += 1
  21.    End Sub
  22.    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
  23. System.EventArgs) Handles Button2.Click
  24.        'backward
  25.        Me.BindingContext(ds.Tables(0)).Position -= 1
  26.    End Sub
  27. End Class

Kerry Moorman
"Cor Ligthert[MVP]" wrote:
>>You can at least use format events

http://www.vb-tips.com/DataBindingEvents.aspx

Cor

"Kyote" <ky********@nospamhotmail.comschreef in bericht
news:k7********************************@4ax.com. ..
I have a textbox that is databound to a table in an access database.
The field only contains month/day/year but my databound textbox is
also showing a time. Is there any way to prevent it from doing this?

---
Kyote

Aug 19 '07 #9

P: n/a
This should do it now.

http://www.vb-tips.com/DataBindingFormatFields.aspx

Cor

"Cor Ligthert[MVP]" <no************@planet.nlschreef in bericht
news:Oq**************@TK2MSFTNGP02.phx.gbl...
It does not show up in the link, we will have a look at the problem.

By hand it is there.

Cor

"Cor Ligthert[MVP]" <no************@planet.nlschreef in bericht
news:ui**************@TK2MSFTNGP04.phx.gbl...
>Kerry,

The new Tip is here

http://www.vb-tips.com/DataBindingFormatFields

Cor

"Kerry Moorman" <Ke**********@discussions.microsoft.comschreef in
bericht news:45**********************************@microsof t.com...
>>Cor,

Here is your example changed to use FormatString and NullValue
properties:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.    Private ds As New DataSet
  3.    Private Sub Form1_Load(ByVal sender As Object, ByVal e As
  4. System.EventArgs) Handles Me.Load
  5.        Dim dt As New DataTable
  6.        ds.Tables.Add(dt)
  7.        dt.Columns.Add("DateField", GetType(System.DateTime))
  8.        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
  9.        dt.LoadDataRow(New Object() {Nothing}, True)
  10.        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)
  11.        Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField",
  12. True)
  13.        Mybinding.FormatString = "MM/dd/yyyy"
  14.        Mybinding.NullValue = "No date"
  15.        TextBox1.DataBindings.Add(Mybinding)
  16.    End Sub
  17.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
  18. System.EventArgs) Handles Button1.Click
  19.        'forward
  20.        Me.BindingContext(ds.Tables(0)).Position += 1
  21.    End Sub
  22.    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
  23. System.EventArgs) Handles Button2.Click
  24.        'backward
  25.        Me.BindingContext(ds.Tables(0)).Position -= 1
  26.    End Sub
  27. End Class

Kerry Moorman
"Cor Ligthert[MVP]" wrote:

You can at least use format events

http://www.vb-tips.com/DataBindingEvents.aspx

Cor

"Kyote" <ky********@nospamhotmail.comschreef in bericht
news:k7********************************@4ax.com ...
I have a textbox that is databound to a table in an access database.
The field only contains month/day/year but my databound textbox is
also showing a time. Is there any way to prevent it from doing this?

---
Kyote

Aug 19 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.