Queries and I are NOT getting along well this week...
Attempting to run an append query from one table to another. The selected table has a field labeled "EmpHireDate." It is a Date/Time data type with an input mask of 99/99/0000;0;_
I am attempting to split the date into month, day, and year via the query and inserting this into corresponding fields in the destination table. Here's what I've got so far (I haven't done anything with the day, yet - not sure how to approach that one):
I had originally tried
but that didn't work, so I tried the more verbose line listed above. With either one of these options I receive a "Type Conversion Error" for all records where the month portion of the string is LESS THAN 2 digits - ie 2 for February.
After playing around, I decided to change the format of EmpHireDate in tblEmpInfo to from "Short Date" to mm/dd/yyyy, thinking that perhaps the query did not like single digits as months. Still didn't work.
My year converts fine, so I'm convinced (perhaps erroneously...?) that there's nothing wrong with the EmpHireDate field.
Any thoughts as to why I'm receiving a type conversion error?
Here's the entire query:
Attempting to run an append query from one table to another. The selected table has a field labeled "EmpHireDate." It is a Date/Time data type with an input mask of 99/99/0000;0;_
I am attempting to split the date into month, day, and year via the query and inserting this into corresponding fields in the destination table. Here's what I've got so far (I haven't done anything with the day, yet - not sure how to approach that one):
Code:
IIf((InStr([tblEmpInfo].[EmpHireDate],"/"))>1,Left([tblEmpInfo].[EmpHireDate],2),Left([tblEmpInfo].[EmpHireDate],1)) AS [Month]
I had originally tried
Code:
Month([tblEmpInfo].[EmpHireDate]) AS [Month]
but that didn't work, so I tried the more verbose line listed above. With either one of these options I receive a "Type Conversion Error" for all records where the month portion of the string is LESS THAN 2 digits - ie 2 for February.
After playing around, I decided to change the format of EmpHireDate in tblEmpInfo to from "Short Date" to mm/dd/yyyy, thinking that perhaps the query did not like single digits as months. Still didn't work.
My year converts fine, so I'm convinced (perhaps erroneously...?) that there's nothing wrong with the EmpHireDate field.
Any thoughts as to why I'm receiving a type conversion error?
Here's the entire query:
Code:
INSERT INTO T_tblAnnivBirth ( EmpName, EmpDay, [Month], [Year] )
SELECT tblEmpInfo.EmpName, tblEmpInfo.EmpHireDate, IIf((InStr([tblEmpInfo].[EmpHireDate],"/"))>1,Left([tblEmpInfo].[EmpHireDate],2),Left([tblEmpInfo].[EmpHireDate],1)) AS [Month], Right([tblEmpInfo.EmpHireDate],4) AS [Year]
FROM tblEmpInfo
WHERE (((tblEmpInfo.EmpJobTitle)="PCA") AND ((tblEmpInfo.EmpActiveState)=-1))
ORDER BY tblEmpInfo.EmpHireDate;