|
-
Jan 24th, 2005, 01:47 PM
#1
Thread Starter
Junior Member
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.
-
Jan 24th, 2005, 02:32 PM
#2
Fanatic Member
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!
-
Jan 24th, 2005, 02:34 PM
#3
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:
Dim dtRentalDate as Date
If txtRentalDate.Text = vbNullString Then
dtRentalDate = Now()
Else
dtRentalDate = txtRentalDate.Text
End If
'Then in you db update code if your passing a SQL string wrap the # chars.
'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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2005, 03:36 PM
#4
Thread Starter
Junior Member
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 value 4.98753117206983E-04)
Should the text box in VB be formatted to date or just plain text?
-
Jan 24th, 2005, 03:38 PM
#5
Thread Starter
Junior Member
Re: Date Type with VB and Access
Hey Rob, thanks for that! Worked a treat
Mark
-
Jan 24th, 2005, 03:39 PM
#6
PowerPoster
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
-
Jan 24th, 2005, 03:42 PM
#7
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jan 24th, 2005, 03:45 PM
#8
Thread Starter
Junior Member
Re: Date Type with VB and Access
-
Jan 24th, 2005, 03:47 PM
#9
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|