473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Runtime error 3421,Data type conversion error

I want to transfer the excel data to th Db ..thru the VBA code.
In the DB there is a table called outer2 containing 1 of the columns as "Upvc" whose format is set to Long integer.

When i try to transfer the data from my excel sheet to Db,I get Data type conversion error..

What do i do to eliminate this error.Below is my vba code for transfer of data frm excel to access
Expand|Select|Wrap|Line Numbers
  1. sub kd()
  2. Dim db As DAO.Database
  3. Dim rs As DAO.Recordset
  4.  
  5. Dim rr As Range
  6. Dim i As Integer
  7. Dim r As Long
  8.  
  9. Set db = DAO.DBEngine.OpenDatabase()
  10.  
  11. Set rs = db.OpenRecordset("outer2", dbOpenDynaset)
  12. MsgBox "done"
  13.  
  14. For r = 2 To 28
  15.  
  16.  
  17. rs.AddNew
  18. rs.Fields(1) = Range("A" & r).Value
  19. rs.Fields(2) = Range("C" & r).Value
  20. rs.Fields(3) = Range("D" & r).Value//error here
  21.  
  22. rs.Update
  23.  
  24. Next r
  25.  
  26. End Sub
Feb 5 '10 #1
4 12552
NeoPa
32,556 Expert Mod 16PB
It might be a good idea for a Data Type Conversion Error to include the offending data.

Please also remember to use the CODE tags. They are not optional and as a full member (next time you post) you will be likely to receive an infraction for further such posts.
Feb 5 '10 #2
TheSmileyCoder
2,322 Expert Mod 2GB
Chances are you have some "offending" data in the field.

1) Start by opening the excel sheet and make sure your input data is correct.
If that doesn't work
2) Change your code to:
Expand|Select|Wrap|Line Numbers
  1. debug.print r & ":(" & Range("D" & r).Value & ")"
  2. rs.Fields(3) = clng(Range("D" & r).Value)
When the code fails, click debug, and look at the immediate window (Ctrl-G) and simply read the largest r value, and the value in parenthesis. The value in parenthesis will be the "problem" value.



In the end, if your sure your data is valid, you could do a clng in front of it (Conversion to long)
Expand|Select|Wrap|Line Numbers
  1. rs.Fields(3) = clng(Range("D" & r).Value)
Feb 5 '10 #3
Thanks alot.As suggested i tried out debugging & the value which i get for the 5th record is 505.6788 in the immediate window.

I think i m getting the error for this value, as the first 2 records fetch the value as 1900 & 1600.The other 2 records are 'having blank values..

So where do i need to make the changes i.e i mean in the table definition what format property do i need to set .Plz guide me...
Feb 6 '10 #4
NeoPa
32,556 Expert Mod 16PB
It would really be handy if you posted the example data as requested. I don't think this value would have a problem converting to Long Integer, but I haven't done exactly this before so maybe it does. If we could see more of the data (not all necessarily, but some lines which must include the data it failed on) then we could have a better chance of identifying the problem.

In the mean-time have you tried Smiley's suggestion of :
Expand|Select|Wrap|Line Numbers
  1. CLng(Range("D" & r))
Feb 7 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tu Quach | last post by:
I got error message like "run time error 3421: data type conversion error" how can i fix the trouble like that, any references should i include in ? any help would be great thank you
7
by: astro | last post by:
Anyone have suggestions on where to troubleshoot this error? Background: -Access 2k v. 9.0.6926 sp3 - front and backend on production server (wiindows 2k) -accessed via Citrix -front-end is...
7
by: Dave Taylor | last post by:
I have a DataTable with three string columns, "Value", "Format" and "Type" However, some of the rows contain numbers and dates in the Value field. So I would like to be able to format the output...
6
by: Ecohouse | last post by:
I have a field in a recordset which is a string. It can look like this: 13-15-67-56 I need to break out this string into numbers to run in queries to open recordsets. But when I try to open...
2
by: Aleksandar | last post by:
Hi, I need to convert set of Java classes exported from IBM Modeling environment to C# for implementation. When I invoke JCLA conversion from File->Open->Convert in Visual Studio 2005 it starts...
7
by: Charlie Brookhart | last post by:
I have a program (posted below) that is supposed to take liters, which is the user input, and convert it to pints and gallons. The pints and gallons are displayed in a read only textbox. I don't...
0
by: audleman | last post by:
I am trying to pass a text string into a stored procedure via a parameter, and am getting the baffling error: adErrDataConversion 3421 You are using a value of the wrong type for the current...
11
by: Kevin Audleman | last post by:
I am trying to pass a text string into a stored procedure via a parameter, and am getting this baffling error while trying to create one of the parameters: adErrDataConversion 3421 You are using...
10
by: gilsygirl | last post by:
Hi Guys Season greetings to everyone. Does anyone have an idea to this error message. Thanks gilsygirl
1
by: elanangaimca | last post by:
Hi 2 all, I am having problem of this 3421 error. The student details are maintained by us. The mobile field may be null on sometimes if the student does't have that number.So i put...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.