[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Insert INTO data mismatch Access field

Posted on 2014-02-18
4
Medium Priority
?
455 Views
Last Modified: 2014-02-21
Hello,

I have a issue with  fields format with Microsoft Access. If I format the field to Currency or Number and use the "Insert Into" I get data type mismatch.
0
Comment
Question by:lincstech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 43

Expert Comment

by:pcelba
ID: 39866813
You should post the INSERT command.

This works for me:
INSERT INTO SomeTable (NumCol1, CurrCol2) VALUES (1, 2) ;
0
 
LVL 61

Accepted Solution

by:
mbizup earned 1000 total points
ID: 39866989
If you are using Visual Basic (per the question's Topic Areas), your SQL statement might look something like this (note the embedded single quotes to delimit text around the values):


strSQL = "INSERT INTO Table1 (TextField1,TextField2) VALUES ('" & Somevalue1 & "','" & SomeValue2 & "')" 

Open in new window


Or this (which uses chr(34) -- quotes-- to delimit text):

strSQL = "INSERT INTO Table1 (TextField1,TextField2) VALUES (" & CHR(34) & Somevalue1 & CHR(34) & "," & CHR(34) & SomeValue2 & CHR(34) & ")" 

Open in new window


If you change the data type of text fields to numeric, you need to drop the quotes (which delimit text) to avoid Type Mismatch errors.    So this would be the correct syntax if your values are currency or other numeric format:

strSQL = "INSERT INTO Table1 (TextField1,TextField2) VALUES (" & Somevalue1 & "," & SomeValue2 & ")" 

Open in new window

0
 
LVL 12

Expert Comment

by:jkaios
ID: 39867016
If I format the field to Currency or Number...

You should leave the values "as is" and not formatting them when inserting into the table.

1234.56 will become $1,234.56 after being formatted to currency style.  The comma separator (and the dollar symbol) will cause your sql INSERT statement to fail.

This works:

INSERT INTO SomeTable (NumCol, CurrencyCol) VALUES (1234, 1234.56) ; 

Open in new window


This will fail:
INSERT INTO SomeTable (NumCol, CurrencyCol) VALUES (1,234, 1,234.56) ; 

Open in new window


This will also fail:
INSERT INTO SomeTable (NumCol, CurrencyCol) VALUES (1,234, $1,234.56) ; 

Open in new window

0
 
LVL 39

Assisted Solution

by:PatHartman
PatHartman earned 1000 total points
ID: 39867281
Formatting is for humans and doesn't affect how a field is stored but formatting will turn a number into a text string and that is why you get type mismatch.  So, you would format for display but not for import (unless you actually want to change the data type).
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What we learned in Webroot's webinar on multi-vector protection.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

656 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