Data Type Mismatch

MHamid

Active Member
Joined
Jan 31, 2013
Messages
472
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I am using the code below to add a record, but I’m getting a run-timeerror ‘3464’: Data type mismatch in criteria expression”. What am I doingwrong? Is it the spaces?

Code:
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]CurrentDb.Execute "INSERT INTO archive_RET_Accumulated([REF_NUM],[Exam ID], [Exam Name], [Exam Agency], [OCC SL No], [Exam Objective], [PrimaryExam Scope DSMT Managed Segment], [Field Work Start Date], [Field Work CompleteDate], [Exam Flag], [Exam Category], [Exam Subcategory], [Exam Owner], [ExamStatus], [Primary Exam Scope DSMT Managed Geography], [Senior Owner],[O&T_Impact], [Exam_Owner_Group_Name], [Exam_Owner_DSMT],[Senior_Owner_Group_Name], [Senior_Owner_DSMT], [RET_Accumulated_Flag],[RET_Accumulated_Added_Date])" & _[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT][FONT=Calibri][SIZE=3][COLOR=#000000]    "VALUES ('" &Me.REF_NUM & "',  '" &Me.Exam_ID & "', '" & Me.Exam_Name & "',  '" & Me.Exam_Agency & "','" & Me.OCC_SL_No & "', '" & Me.Exam_Objective &"', '" & Me.Primary_Exam_Scope_DSMT_Managed_Geography &"', '" & Me.Field_Work_Start_Date & "', '" &Me.Field_Work_Complete_Date & "', '" & Me.Exam_Flag &"', '" & Me.Exam_Category & "', '" &Me.Exam_Subcategory & "', '" & Me.Exam_Owner &"','" & Me.Exam_Status & "', '" &Me.Primary_Exam_Scope_DSMT_Managed_Geography & "', '" &Me.Senior_Owner & "', '" & Me.OT_Impact & "','" & Me.Exam_Owner_Group_Name & "', '" &Me.Exam_Owner_DSMT & "', """ &Me.Senior_Owner_Group_Name & """, '" &Me.Senior_Owner_DSMT & "', '" & Me.RET_Accumulated_Flag &"', '" & Me.RET_Accumulated_Added_Date & "');",dbFailOnError


Thank you

 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Too many fields to know.

You need to debug your string. Try putting this into your form and then check out the results (maybe just use a temp button to run it).

Code:
sub foo()

dim strSQL as string

strSQl = "INSERT INTO archive_RET_Accumulated([REF_NUM],[Exam ID], [Exam Name], [Exam Agency], [OCC SL No], [Exam Objective], [PrimaryExam Scope DSMT Managed Segment], [Field Work Start Date], [Field Work CompleteDate], [Exam Flag], [Exam Category], [Exam Subcategory], [Exam Owner], [ExamStatus], [Primary Exam Scope DSMT Managed Geography], [Senior Owner],[O&T_Impact], [Exam_Owner_Group_Name], [Exam_Owner_DSMT],[Senior_Owner_Group_Name], [Senior_Owner_DSMT], [RET_Accumulated_Flag],[RET_Accumulated_Added_Date])" & _
    "VALUES ('" &Me.REF_NUM & "',  '" &Me.Exam_ID & "', '" & Me.Exam_Name & "',  '" & Me.Exam_Agency & "','" & Me.OCC_SL_No & "', '" & Me.Exam_Objective &"', '" & Me.Primary_Exam_Scope_DSMT_Managed_Geography &"', '" & Me.Field_Work_Start_Date & "', '" &Me.Field_Work_Complete_Date & "', '" & Me.Exam_Flag &"', '" & Me.Exam_Category & "', '" &Me.Exam_Subcategory & "', '" & Me.Exam_Owner &"','" & Me.Exam_Status & "', '" &Me.Primary_Exam_Scope_DSMT_Managed_Geography & "', '" &Me.Senior_Owner & "', '" & Me.OT_Impact & "','" & Me.Exam_Owner_Group_Name & "', '" &Me.Exam_Owner_DSMT & "', """ &Me.Senior_Owner_Group_Name & """, '" &Me.Senior_Owner_DSMT & "', '" & Me.RET_Accumulated_Flag &"', '" & Me.RET_Accumulated_Added_Date & "');" 
	
debug.print strSQl

end sub

Not sure if its the html or your actual code but there are some cases with no space after the & operator. Also all string, date, and number types need to be handled differently in literal sql commands (strings need single quotes around them ('a string'), dates need octothorpes around them (#1/1/2018#) and numbers don't need anything around them.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top