473,513 Members | 7,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
9 2387
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6277
by: Joe User | last post by:
Hi all....I have a feeling this is going to be one of those twisted query questions, but here it goes anyways.... I want to generate a report that shows the chronology of events (represented by...
4
5325
by: Jan Nielsen | last post by:
Hi I have a dataform that shows a date from a MSDE 2000 in a textbox. It uses the format: dd-mm-yyyy hh:mm:ss It would it to use the format dd-mm-yyyy But I can't find a Format property for the...
1
1223
by: Bob | last post by:
Hello: I have an untyped dataset that uses an Access 2002 database. For every record, it shows mm/dd/yyyy 12:00:00 AM in the textbox. All I want to show is mm/dd/yyyy I don't even know...
3
3274
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
10
2808
by: sandraz444 | last post by:
I have an expression in the query under my form to autofill the date under a certain condition but it wont write to the underlying table?? The date shows in the form but not the table. Does anyone...
2
3759
by: Luqman | last post by:
Hi, Any Idea how to Display Todays Date in DetailView Template Field while Inserting ? For example: When I click on New Button of DetailView Control, I need to display Today's Date in a...
7
10163
by: sheri | last post by:
I have a field called date, the date is in the field like this 70925 (which means Sept. 25, 2007). I have another field called day, it is a text field. How do I write a query to populate the day...
4
2869
by: Allen Browne | last post by:
Paul, you *really* need to head Stuart's advice. The data types are crucially important in database fields. Non-date values (like the 3 letters TBC) are not valid dates, and cannot be evaluated...
4
3035
by: =?Utf-8?B?ZGNoMw==?= | last post by:
Is there a way to conditionally format a dateTime field to produce on result if the value is 10/31/2008 12:00 AM (user didn't enter a time) and another result if the value is 10/31/2008 5:30 PM...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.