473,406 Members | 2,467 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,406 software developers and data experts.

AS400 DB2 Data Type Conversion Error

I am reporting on data from DB2/AS400. I created simple queries that run on a regular MS Access query and a Pass through query.

I could get the VBA to open the file without a query string and loop through the recordset 1 record at a time. I can't get a query string to work.

Every combination I've tried using a SQL query string produces Run Time Error 3421 - Data type conversion error. As you can see, I'm using a trial of just a single field. I have tried both a string field and numeric field.

Yesterday I searched through every posting I could find on MS ACCESS / DB2 and could not find an example with code provided.

Here is my VBA code with the different combinations I've tried:
Expand|Select|Wrap|Line Numbers
  1. Sub PassThroughLoop()
  2.  
  3.     Dim sSQL As String
  4.     Dim rst As DAO.Recordset
  5.  
  6. '   AS400 SQL
  7. '    sSQL = "SELECT BJDOCD FROM ID3SCVDTA.COVDTLP WHERE ID3SCVDTA.COVDTLP.BJDOCD='00CC157640'"
  8.     sSQL = "SELECT ID3SCVDTA.COVDTLP.BJACSG FROM ID3SCVDTA.COVDTLP WHERE ID3SCVDTA.COVDTLP.BJACSG=1298677"
  9.  
  10. '   MS Access SQL
  11. '    sSQL = "SELECT ID3SCVDTA_COVDTLP.BJDOCD FROM ID3SCVDTA_COVDTLP WHERE ID3SCVDTA_COVDTLP.BJDOCD ='00CC157640'"
  12. '    sSQL = "SELECT ID3SCVDTA_COVDTLP.BJACSG FROM ID3SCVDTA_COVDTLP WHERE ID3SCVDTA_COVDTLP.BJACSG=1298677;"
  13. 'MsgBox "sSQL string is: " & sSQL
  14.  
  15.     Set rst = CurrentDb.TableDefs("ID3SCVDTA_COVDTLP").OpenRecordset(sSQL)
  16.  
  17.     With rst
  18.         .MoveFirst
  19.         Do Until .EOF
  20.             MsgBox "Policy " & rst!BJDOCD
  21.             .MoveNext
  22.         Loop
  23.     End With
  24.  
  25.     rst.Close
  26.     Set rst = Nothing
  27. End Sub
  28.  
This looks like a helpful group and I would be thankful for help and advice.
Mar 3 '17 #1

✓ answered by PhilOfWalton

OK I think I see your problem

Add yo your code
Expand|Select|Wrap|Line Numbers
  1.     Dim MyDb as Database
  2.  
  3.     Set MyDb = CurrentDb
  4.  
  5.  
Change
Set rst = CurrentDb.TableDefs("ID3SCVDTA_COVDTLP").OpenRecor dset(sSQL)
to

Set Rst = MyDb.OpenRecordSet(sSQL)

Now there is obviously confusion on the table name. It is whatever it shows up as in your list of tables in the navigation pane.

The format of your SQL should be (to get all the fields)
sSQL = "SELECT MyTableName.* FROM MyTableName WHERE ......."


Phil

4 942
PhilOfWalton
1,430 Expert 1GB
Your MsgBox is asking to display the value of rst!BJDOCD, but that field is nor defined in your SQL in the one you are currently using (but is defined in the first SQL attempt).

What is the name of your table. In some places it appears to be ID3SCVDTA.COVDTLP with a dot, and in other places ID3SCVDTA_COVDTLP with an underscore.

I am reasonably sure that ID3SCVDTA.COVDTLP with a dot is an illegal table name.

My guess is (Note 2 underscores)
Expand|Select|Wrap|Line Numbers
  1. sSQL = "SELECT BJDOCD FROM ID3SCVDTA_COVDTLP WHERE ID3SCVDTA_COVDTLP.BJDOCD='00CC157640'"
  2.  
Phil
Mar 3 '17 #2
Thanks for the hint and looking at this. I tried replacing the . with _ and I still get the same Run-time error '3421': Data Type Conversion error. I'm using table COVDTLP in the AS400 database. If I paste the sSQL string into an Access Pass Through query it runs with . but not with _ I changed the message box, though the code doesn't get to here yet. It errors on: Set rst = CurrentDb.TableDefs("ID3SCVDTA_COVDTLP").OpenRecor dset(sSQL).

The table opens if I change the statement to: Set rst = CurrentDb.TableDefs("ID3SCVDTA_COVDTLP").OpenRecor dset but that doesn't help me as I am using the SQL to get just 3 records (in this case). I simplified the code some and tried the sSQL string with both . and _
Expand|Select|Wrap|Line Numbers
  1. Sub PassThroughLoop()
  2. '   3/2/2017 - SJ - This sort of works. The dataset is opened and it moves through each record without the sSQL string.
  3.     Dim sSQL As String
  4.     Dim rst As DAO.Recordset
  5.  
  6. '   AS400 SQL
  7. '    sSQL = "SELECT BJDOCD FROM ID3SCVDTA.COVDTLP WHERE ID3SCVDTA.COVDTLP.BJDOCD='00CC157640'"
  8.     sSQL = "SELECT BJACSG FROM ID3SCVDTA.COVDTLP WHERE BJACSG=1298677"
  9.  
  10. '   MS Access SQL
  11. '    sSQL = "SELECT ID3SCVDTA_COVDTLP.BJDOCD FROM ID3SCVDTA_COVDTLP WHERE ID3SCVDTA_COVDTLP.BJDOCD ='00CC157640'"
  12. '    sSQL = "SELECT ID3SCVDTA_COVDTLP.BJACSG FROM ID3SCVDTA_COVDTLP WHERE ID3SCVDTA_COVDTLP.BJACSG=1298677;"
  13. MsgBox "sSQL string is: " & sSQL
  14.  
  15.     Set rst = CurrentDb.TableDefs("ID3SCVDTA_COVDTLP").OpenRecordset(sSQL)
  16.  
  17.     With rst
  18.         .MoveFirst
  19.         Do Until .EOF
  20.             MsgBox "Key " & rst!BJACSG
  21.             .MoveNext
  22.         Loop
  23.     End With
  24.  
  25.     rst.Close
  26.     Set rst = Nothing
  27. End Sub
  28.  
Mar 4 '17 #3
PhilOfWalton
1,430 Expert 1GB
OK I think I see your problem

Add yo your code
Expand|Select|Wrap|Line Numbers
  1.     Dim MyDb as Database
  2.  
  3.     Set MyDb = CurrentDb
  4.  
  5.  
Change
Set rst = CurrentDb.TableDefs("ID3SCVDTA_COVDTLP").OpenRecor dset(sSQL)
to

Set Rst = MyDb.OpenRecordSet(sSQL)

Now there is obviously confusion on the table name. It is whatever it shows up as in your list of tables in the navigation pane.

The format of your SQL should be (to get all the fields)
sSQL = "SELECT MyTableName.* FROM MyTableName WHERE ......."


Phil
Mar 4 '17 #4
You are awesome Phil. Thank you. Your suggestions work as you expected. I'm getting the records I'm expecting to see. Now I can go on to build a more complicated query. Here is my code that works in the event someone searches for the same thing:
Expand|Select|Wrap|Line Numbers
  1. Sub PassThroughLoop()
  2. '   3/6/2017 - SJ - This code opens a DB2 table when you have the correct ODBC connection. The database table is opened and the code moves through each record returned with the sSQL string.
  3.     Dim sSQL As String
  4.     Dim rst As DAO.Recordset
  5.     Dim MyDb As Database
  6.  
  7.     Set MyDb = CurrentDb
  8.  
  9.     sSQL = "SELECT ID3SCVDTA_COVDTLP.* FROM ID3SCVDTA_COVDTLP WHERE BJACSG=1298677"
  10.  
  11. 'MsgBox "sSQL string is: " & sSQL
  12.  
  13.     Set rst = MyDb.OpenRecordset(sSQL)
  14.  
  15.     With rst
  16.         .MoveFirst
  17.         Do Until .EOF
  18.             MsgBox "Key " & rst!BJDOCD & " " & rst!BJACSG
  19.             .MoveNext
  20.         Loop
  21.     End With
  22.  
  23.     rst.Close
  24.     Set rst = Nothing
  25. End Sub
  26.  
Mar 6 '17 #5

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

Similar topics

8
by: CAFxX | last post by:
i'm writing a program that executes some calculations on a bitmap loaded in memory. these calculation ends up with pixel wth values far over 255, but i need them to be between 0 and 255 since i...
0
by: news.paradise.net.nz | last post by:
I have been developing access databases for over 5 years. I have a large database and I have struck this problem with it before but can find nothing in help or online. Access 2000 I have a query...
2
by: Smith John | last post by:
Here is my ASP.Net code "If CustomerCMD.Parameters("@Checkout").Value = 0 Then" Since I set the option strict on.... It is throwing type missmatch error. @Checkout is a "tinyinteger" in SQL...
2
by: preeti13 | last post by:
i am tring to retrive the value form the data base but getting erorr i tried so many way but i didn't get the value i got the erorr like this: Implicit conversion from data type datetime to int is...
16
by: The Frog | last post by:
Hi Everyone, I have a small problem that doesnt seem to make any sense. I am using Access 97, and have a query that selects data from a text field, converts it to type Lng. This seems to work...
10
by: gilsygirl | last post by:
Hi Guys Season greetings to everyone. Does anyone have an idea to this error message. Thanks gilsygirl
5
by: Lewe22 | last post by:
why would i be seeing a 'Data type conversion' error when saving records to a table on 1 machine, but when saving the exact same record from a number of different machines it works fine. All machines...
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...
4
by: shalskedar | last post by:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.