Solved

Convert date from string to date/time

Posted on 2008-06-10
3
3,912 Views
Last Modified: 2013-11-27
I'm trying to take the value in a textbox on a form into a table using an update statement.  The textbox value is populated by a calendar control, but when this is passed into the date/time field in the table, something strange is happening.

For example, a date in the textbox of 15/01/2008 will appear as that in the table (i'm using uk format i.e. dd/mm/yyyy).  However if the date in the textbox is 10/01/2008 (i.e. the day value is under 12) it appears in the table as 01/10/2008, so has defaulted to mm/dd/yyyy.

I've tried using both CDate and Convert functions, but this seems to fill the table with time data, for example 00:01:10!  

By the way i've tried the WE variable in the sql statement with and without the #, and also dim'd the WE as both Date and String, with the same issues.

Thanks
Dim SubID As String

Dim WE As Date

Dim SQL As String
 

SubID = [Forms]![frm_Expenses]![SubID]

WE = [Forms]![frm_Expenses]![cboWeekEnding]
 

SQL = "UPDATE dbo_tbl_Weekly_Expenses_Temp SET [Week Ending] = #" & WE & "# WHERE Submission_ID = " & SubID
 

DoCmd.RunSQL (SQL)

Open in new window

0
Comment
Question by:grunners80
3 Comments
 
LVL 77

Accepted Solution

by:
peter57r earned 125 total points
Comment Utility
SET [Week Ending] = #" & format(WE, "yyyy-mm-dd") & "# WHERE
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
if [Week Ending] in your table is text, use:

SET [Week Ending] = '" & format(WE, "yyyy-mm-dd") & "' WHERE

if [Week Ending] in your table is date/time, use:

SET [Week Ending] = #" & WE  "# WHERE

or

SET [Week Ending] = #" & Cdate(WE)  "# WHERE

Mike
0
 

Author Closing Comment

by:grunners80
Comment Utility
Many thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now