I am writing code to import assessment information about a building from an Excel file (populated by a mobile interviewer on a laptop) into an Access database. With much trial and error, I've hit upon a way of importing all the necessary information, but have run into one last problem when establishing my fully-prepared temporary table to use for appending to the permanent assessment data table.
One of the fields in the form, AImportDate, is a date/time field without a specified format. I have obtained the value of the assessment date and stored it as a variable dtDate, Dim'd as Date. For my test file, dtDate properly returns '05/03/2010' (5 March). I then run the following SQL command:
Bizarrely, this causes AImportDate for all of the records in the table to be updated with a value of '00:01:12', not a date at all, and certainly not the right one (if I change the format to Short Date in the table design, they show as '30/12/1899'). Yet if I manually type the date into the table, even after the update in the code, it displays correctly.
I had created the table with this SQL statement earlier in the module:
Does anyone know why this problem would be occurring? And the best way to circumvent it? Thanks.
One of the fields in the form, AImportDate, is a date/time field without a specified format. I have obtained the value of the assessment date and stored it as a variable dtDate, Dim'd as Date. For my test file, dtDate properly returns '05/03/2010' (5 March). I then run the following SQL command:
Code:
strSQL = "UPDATE " & strWriteTable & " " _
& "SET AImportPropIndex = " & intPropIndex & ", " _
& "AImportDate = " & dtDate & ";"
'DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
I had created the table with this SQL statement earlier in the module:
Code:
strSQL = "CREATE TABLE " & strWriteTable & " " _
& "(AImportIndex INT, " _
& "AssessmentItemIndex INT NOT NULL, " _
& "AssessmentRShort INT, " _
& "AssessmentRFreeText TEXT(255), " _
& "AssessmentRComment TEXT(255), " _
& "AImportPropIndex INT, " _
& "AImportDate DATETIME, " _
& "PRIMARY KEY (AImportIndex));"
DoCmd.RunSQL strSQL
Comment