PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

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

 
 
Kyote
Guest
Posts: n/a
 
      16th Aug 2007
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
 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      16th Aug 2007
You can at least use format events

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

Cor

"Kyote" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
>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


 
Reply With Quote
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      16th Aug 2007
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
 
Reply With Quote
 
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
Posts: n/a
 
      17th Aug 2007
Cor,

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

Code:
Public Class Form1

Private ds As New DataSet

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("DateField", GetType(System.DateTime))
dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
dt.LoadDataRow(New Object() {Nothing}, True)
dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)

Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField", True)
Mybinding.FormatString = "MM/dd/yyyy"
Mybinding.NullValue = "No date"
TextBox1.DataBindings.Add(Mybinding)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

'forward
Me.BindingContext(ds.Tables(0)).Position += 1

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

'backward
Me.BindingContext(ds.Tables(0)).Position -= 1

End Sub
End Class
Kerry Moorman


"Cor Ligthert[MVP]" wrote:

> You can at least use format events
>
> http://www.vb-tips.com/DataBindingEvents.aspx
>
> Cor
>
> "Kyote" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
> >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

>
>

 
Reply With Quote
 
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
Posts: n/a
 
      17th Aug 2007
Cor,

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

Code:
Public Class Form1

Private ds As New DataSet

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add("DateField", GetType(System.DateTime))
dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
dt.LoadDataRow(New Object() {Nothing}, True)
dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)

Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField", True)
Mybinding.FormatString = "MM/dd/yyyy"
Mybinding.NullValue = "No date"
TextBox1.DataBindings.Add(Mybinding)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

'forward
Me.BindingContext(ds.Tables(0)).Position += 1

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click

'backward
Me.BindingContext(ds.Tables(0)).Position -= 1

End Sub
End Class
Kerry Moorman


"Cor Ligthert[MVP]" wrote:

> You can at least use format events
>
> http://www.vb-tips.com/DataBindingEvents.aspx
>
> Cor
>
> "Kyote" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
> >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

>
>

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      17th Aug 2007
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" <(E-Mail Removed)> schreef in bericht
news:4556C419-DB82-4A69-BA80-(E-Mail Removed)...
> Cor,
>
> Here is your example changed to use FormatString and NullValue properties:
>
>
Code:
> Public Class Form1
>
>    Private ds As New DataSet
>
>    Private Sub Form1_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Me.Load
>
>        Dim dt As New DataTable
>        ds.Tables.Add(dt)
>        dt.Columns.Add("DateField", GetType(System.DateTime))
>        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
>        dt.LoadDataRow(New Object() {Nothing}, True)
>        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)
>
>        Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField",
> True)
>        Mybinding.FormatString = "MM/dd/yyyy"
>        Mybinding.NullValue = "No date"
>        TextBox1.DataBindings.Add(Mybinding)
>
>    End Sub
>
>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>
>        'forward
>        Me.BindingContext(ds.Tables(0)).Position += 1
>
>    End Sub
>
>    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
>
>        'backward
>        Me.BindingContext(ds.Tables(0)).Position -= 1
>
>    End Sub
> End Class
>
>
> Kerry Moorman
>
>
> "Cor Ligthert[MVP]" wrote:
>
>> You can at least use format events
>>
>> http://www.vb-tips.com/DataBindingEvents.aspx
>>
>> Cor
>>
>> "Kyote" <(E-Mail Removed)> schreef in bericht
>> news:(E-Mail Removed)...
>> >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

>>
>>


 
Reply With Quote
 
Kyote
Guest
Posts: n/a
 
      17th Aug 2007
On Thu, 16 Aug 2007 20:21:50 +0200, "Cor Ligthert[MVP]"
<(E-Mail Removed)> wrote:

>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
 
Reply With Quote
 
Kyote
Guest
Posts: n/a
 
      17th Aug 2007
On Thu, 16 Aug 2007 21:00:36 +0200, Göran Andersson <(E-Mail Removed)>
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
 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      19th Aug 2007
Kerry,

The new Tip is here

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

Cor

"Kerry Moorman" <(E-Mail Removed)> schreef in bericht
news:4556C419-DB82-4A69-BA80-(E-Mail Removed)...
> Cor,
>
> Here is your example changed to use FormatString and NullValue properties:
>
>
Code:
> Public Class Form1
>
>    Private ds As New DataSet
>
>    Private Sub Form1_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Me.Load
>
>        Dim dt As New DataTable
>        ds.Tables.Add(dt)
>        dt.Columns.Add("DateField", GetType(System.DateTime))
>        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
>        dt.LoadDataRow(New Object() {Nothing}, True)
>        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)
>
>        Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField",
> True)
>        Mybinding.FormatString = "MM/dd/yyyy"
>        Mybinding.NullValue = "No date"
>        TextBox1.DataBindings.Add(Mybinding)
>
>    End Sub
>
>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>
>        'forward
>        Me.BindingContext(ds.Tables(0)).Position += 1
>
>    End Sub
>
>    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button2.Click
>
>        'backward
>        Me.BindingContext(ds.Tables(0)).Position -= 1
>
>    End Sub
> End Class
>
>
> Kerry Moorman
>
>
> "Cor Ligthert[MVP]" wrote:
>
>> You can at least use format events
>>
>> http://www.vb-tips.com/DataBindingEvents.aspx
>>
>> Cor
>>
>> "Kyote" <(E-Mail Removed)> schreef in bericht
>> news:(E-Mail Removed)...
>> >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

>>
>>


 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      19th Aug 2007
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]" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> Kerry,
>
> The new Tip is here
>
> http://www.vb-tips.com/DataBindingFormatFields
>
> Cor
>
> "Kerry Moorman" <(E-Mail Removed)> schreef in
> bericht news:4556C419-DB82-4A69-BA80-(E-Mail Removed)...
>> Cor,
>>
>> Here is your example changed to use FormatString and NullValue
>> properties:
>>
>>
Code:
>> Public Class Form1
>>
>>    Private ds As New DataSet
>>
>>    Private Sub Form1_Load(ByVal sender As Object, ByVal e As
>> System.EventArgs) Handles Me.Load
>>
>>        Dim dt As New DataTable
>>        ds.Tables.Add(dt)
>>        dt.Columns.Add("DateField", GetType(System.DateTime))
>>        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 4)}, True)
>>        dt.LoadDataRow(New Object() {Nothing}, True)
>>        dt.LoadDataRow(New Object() {New DateTime(2005, 8, 5)}, True)
>>
>>        Dim Mybinding As New Binding("Text", ds.Tables(0), "DateField",
>> True)
>>        Mybinding.FormatString = "MM/dd/yyyy"
>>        Mybinding.NullValue = "No date"
>>        TextBox1.DataBindings.Add(Mybinding)
>>
>>    End Sub
>>
>>    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles Button1.Click
>>
>>        'forward
>>        Me.BindingContext(ds.Tables(0)).Position += 1
>>
>>    End Sub
>>
>>    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles Button2.Click
>>
>>        'backward
>>        Me.BindingContext(ds.Tables(0)).Position -= 1
>>
>>    End Sub
>> End Class
>>
>>
>> Kerry Moorman
>>
>>
>> "Cor Ligthert[MVP]" wrote:
>>
>>> You can at least use format events
>>>
>>> http://www.vb-tips.com/DataBindingEvents.aspx
>>>
>>> Cor
>>>
>>> "Kyote" <(E-Mail Removed)> schreef in bericht
>>> news:(E-Mail Removed)...
>>> >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
>>>
>>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access query on date/TIme field for date then there is no time? =?Utf-8?B?QmFuaw==?= Microsoft Access Queries 12 23rd Feb 2006 10:02 PM
RE: Access query on date/TIme field for date then there is no time? =?Utf-8?B?S0FSTCBERVdFWQ==?= Microsoft Access Queries 0 4th Feb 2006 11:48 AM
Time shows up in mail merge date field =?Utf-8?B?QUdNUHJlYWNoZXI=?= Microsoft Access 1 1st Jun 2005 04:25 AM
Editing a textbox with a smalldatetime control source shows date and time Wes Peters Microsoft Access ADP SQL Server 6 6th Feb 2005 09:15 AM
DB2/400 ODBC time field to MS Access 2000 date/time field mapping error. Kaj Julius Microsoft Access External Data 4 4th Dec 2003 01:31 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:45 AM.