473,758 Members | 2,311 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 2428
You can at least use format events

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

Cor

"Kyote" <ky********@nos pamhotmail.coms chreef in bericht
news:k7******** *************** *********@4ax.c om...
>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********@nos pamhotmail.coms chreef in bericht
news:k7******** *************** *********@4ax.c om...
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**********@d iscussions.micr osoft.comschree f in bericht
news:45******** *************** ***********@mic rosoft.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********@nos pamhotmail.coms chreef 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.co m>
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**********@d iscussions.micr osoft.comschree f in bericht
news:45******** *************** ***********@mic rosoft.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********@nos pamhotmail.coms chreef 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.nlschre ef in bericht
news:ui******** ******@TK2MSFTN GP04.phx.gbl...
Kerry,

The new Tip is here

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

Cor

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.comschree f in
bericht news:45******** *************** ***********@mic rosoft.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********@nos pamhotmail.coms chreef 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.nlschre ef in bericht
news:Oq******** ******@TK2MSFTN GP02.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.nlschre ef in bericht
news:ui******** ******@TK2MSFTN GP04.phx.gbl...
>Kerry,

The new Tip is here

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

Cor

"Kerry Moorman" <Ke**********@d iscussions.micr osoft.comschree f in
bericht news:45******** *************** ***********@mic rosoft.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********@nos pamhotmail.coms chreef in bericht
news:k7***** *************** ************@4a x.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
6293
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 field names). Essentially, I would like to sort the DATE FIELDS for each record in the table by the order of the DATES in those DATE FIELDS. For example: record ID= 354
4
5348
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 textbox. So I tried in the VB code the wizard generates Me.editDateOfBirth.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.objDSBoerneKirken, "tPersoner.DateOfBirth")) Me.editDateOfBirth.Location = New System.Drawing.Point(120, 604)
1
1257
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 where it's getting the 12:00:00 AM from. I checked the raw data in the table and only a short date is in each field but my app keeps
3
3313
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 the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
10
2850
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 know a solution for this? Thanks!
2
3766
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 Template Field text box. I tried following in DetailView1_ModeChanged Event but could not succeed. Protected Sub DetailsView1_ModeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.ModeChanged
7
10189
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 field from the date field? Thanks for your help.
4
2912
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 as dates. On the other hand, Null is a valid and very meaningful value. It will be processed correctly when you do things like counting the number of dates in the field, averaging, or finding the nearest date. Using a fake date (such as...
4
3050
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 (user entered a time). I'm looking for this result... Value Result 10/31/2008 12:00 AM FRI 10/31/08 10/31/2008 12:01 AM FRI 10/31/08 12:01 AM I also need to figure out the cell spacing to force the time...
0
9492
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9299
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10076
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9740
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8744
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7287
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5332
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3832
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 we have to send another system

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.