Data Type Mismatch

MHamid

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

I am getting a data type mismatch in my code below.

Code:
CurrentDb.Execute "INSERT INTO QAMaster([Cycle Month],[Report Type],[Date Reviewed],[Reviewer Type],[Reviewer],[Reviewer Report Area],[Main Section],[Topic Section],[Ownership],[Count],[Priority],[QA Update],[L1],[L2],[L3],[Exception],[Notes],[Outliers])" & _
    "VALUES ('" & Me.CycleMonth & "', '" & Me.ReportType & "', '" & Me.DateReviewed & "', '" & Me.ReviewerType & "', '" & Me.Reviewer & "', '" & Me.ReviewerReportArea & "', '" & Me.MainSection & "', '" & Me.TopicSection & "', '" & Me.Ownership & "', '" & Me.Count & "', '" & Me.Priority & "', '" & Me.QAUpdate & "', '" & Me.L1 & "', '" & Me.L2 & "', '" & Me.L3 & "', '" & Me.Exceptions & "', '" & Me.Notes & "', '" & Me.Outliers & "');", dbFailOnError

All values except for Date Reviewed, Count, Notes, QA Update and Exceptions are combo boxes. Date Reviewed is a date option ... count and notes is a text box, and QA Update and Exceptions are check boxes.

What am I missing in my code?

Thank you
 
Are L1,L2 & l3 numeric?. If not they will need the single quotes that you have used for the other fields like Me.Exceptions

Edit:
So you are putting quotes around numbers? Me.Exceptions and not text like Me.L1 ??
 
Last edited:
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hello,

L1, L2 and L3 are not numeric.

I am not sure exactly what I did, but the code works now.

Code:
Private Sub Add_Record_Click()
CurrentDb.Execute "INSERT INTO QAMaster([Cycle Month], [Report Type], [Date Reviewed], [Reviewer Type], [Reviewer], [Reviewer Report Area], [Main Section], [Topic Section], [Ownership], [Count], [Priority], [QA Update], [L1], [L2], [L3], [Exception], [Notes], [Outliers])" & _
    "VALUES ('" & Me.CycleMonth & "', '" & Me.ReportType & "', '" & Me.DateReviewed & "', '" & Me.ReviewerType & "', '" & Me.Reviewer & "', '" & Me.ReviewerReportArea & "', '" & Me.MainSection & "', '" & Me.TopicSection & "', '" & Me.Ownership & "', '" & Me.txtCount & "', '" & Me.PriorityLevel & "', '" & Me.QAUpdate & "', '" & Me.L1 & "', '" & Me.L2 & "', '" & Me.L3 & "', '" & Me.Exception & "', '" & Me.Notes & "', '" & Me.Outliers & "');", dbFailOnError
MsgBox "Record Added Successfully", vbInformation, "SUCCESS!"
End Sub

I think I ended up putting single quotes around everything. It looks like L3 was pulling data from the L2 column.

Now the next issue I have to figure out is getting the check boxes to be entered into the table as a check mark instead of a number.

Thank you
 
Upvote 0
I believe leaving them as a number will set the checkmark.
For strings you need to surround them with quotes, normally single quotes when you are constructing SQL like you are doing here. For numbers leave quotes out of it, so me.Exceptions would be

Code:
& Me.Exceptions

and for L1 etc it would be
Code:
& "'" & Me.L1 & "'"
 
Upvote 0
0, False and No are the same. 1, True and Yes are the same. Doesn't matter which way the table is formatted, the checkbox will behave accordingly.
FWIW, the issue of quotes around text was raised early on.
 
Upvote 0
Looking back at post 10 and 12, I think you need a space before the word "VALUES" in all those lines.
 
Last edited:
Upvote 0
Hello,

The code that I posted in post#12 does what I need it to do. I was also able to get my check boxes to be added to the table as check boxes instead of numbers.

Thank you all for your help.

I'm on to another task in my form.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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