Results 1 to 9 of 9

Thread: Date Type with VB and Access[Resolved]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    17

    Date Type with VB and Access[Resolved]

    I want to take an inputted date from a text box, convert it to a date datatype then send it to my access database.

    The data type of the Access field was text and then date, both of which didnt record the correct figures.

    My program is sending the data to the db but it is captured incorrectly. i.e. Its being stored as an abstract time (00:00:43) or code(4.99001996007984E-04).

    Heres my code:

    Dim dtRentalDate as Date

    If txtRentalDate.Text = "" Then
    dtRentalDate = Now()
    Else: dtRentalDate = txtRentalDate.Text
    End If


    Please help
    Last edited by trackdaychamp; Jan 24th, 2005 at 05:03 PM.

  2. #2
    Fanatic Member demotivater's Avatar
    Join Date
    Jun 2002
    Location
    is everything
    Posts
    627

    Re: Date Type with VB and Access

    Try formatting the input before you send it to the database

    ie:

    dtRentalDate = Format(dtRentalDate, "mm/dd/yyyy")
    Here's to us!
    Who's like us?
    Darned few, and they're all dead!

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Date Type with VB and Access

    If the date type for the field in the db is a Date/Time field then you need to
    pass the date wrapped with the "#" character. Also you shouldn't use the
    colon in your code as it acts as a carraige return.

    VB Code:
    1. Dim dtRentalDate as Date
    2.  
    3. If txtRentalDate.Text = vbNullString Then
    4.     dtRentalDate = Now()
    5. Else
    6.     dtRentalDate = txtRentalDate.Text
    7. End If
    8.  
    9. 'Then in you db update code if your passing a SQL string wrap the # chars.
    10. 'If your using the .Update method of a rs then dont.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    17

    Question Re: Date Type with VB and Access

    I tried exactly what you suggested but the outcome was unfortunately the same:

    The db was showing the value4.98753117206983E-04)

    Should the text box in VB be formatted to date or just plain text?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    17

    Thumbs up Re: Date Type with VB and Access

    Hey Rob, thanks for that! Worked a treat

    Mark

  6. #6
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Date Type with VB and Access

    I would try:

    Dim dtRentalDate as Date

    If txtRentalDate.Text = vbNullString Then
    dtRentalDate = Now()
    Else
    dtRentalDate = cdate(txtRentalDate.Text)
    End If

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Date Type with VB and Access

    No prob. Glad to help.
    Dont forget to Resolve your thread if its working now.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    17

    Resolved Re: Date Type with VB and Access

    Matter is resolved

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Date Type with VB and Access

    You need to edit your first post and either change the subject icon to the
    green check mark or add "Resolved" to the subject.

    This will allow it to be seen at the forum view level instead at the post view level.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width