473,396 Members | 1,933 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,396 software developers and data experts.

Update table in as400 using table in excel worksheet

4
I want to update table in as400 using table in excel worksheet like this :
Table1 [as400]
Expand|Select|Wrap|Line Numbers
  1. REFNO      I        QTY
  2. 1          I        10
  3. 2          I        12 
  4. 3          I        20   
Table2 [excel worksheet]
Expand|Select|Wrap|Line Numbers
  1. REFNO      I       QTY
  2. 1          I       13
  3. 2          I       15 
  4. 3          I       22
Qty in Table1 updated from Table2 using VBA so the ouput will be like this :
Expand|Select|Wrap|Line Numbers
  1. Table1 [as400]
  2. REFNO      I       QTY
  3. 1          I      13
  4. 2          I       15 
  5. 3          I       22
I have used inner join code like this :
Expand|Select|Wrap|Line Numbers
  1. Dim s1 As Worksheet
  2. Dim BRDa As ADODB.Connection
  3. Dim RS As ADODB.Recordset
  4. Dim b As Integer
  5.  
  6. Set RS = New ADODB.Recordset
  7. Set BRDa = New ADODB.Connection
  8. BRDa.ConnectionString = "provider=ABC; Data source=XYZ; user id=OK1; password=OK2"
  9. BRDa.Open
  10.  
  11. On Error Resume Next 
  12. Dim QRY1, QRY2 As String
  13. QRY1 = "SELECT * FROM TABLE1 INNER JOIN S1.TABLE2 ON TABLE1.REFNO=TABLE2.REFNO"
  14. RS.Open QRY1, BRDa, adOpenDynamic, adLockOptimistic
  15.  
  16. b = 0
  17.  
  18. Do While Not RS.EOF
  19. QRY2 = "UPDATE TABLE1 SET TABLE1.QTY = TABLE2.QTY WHERE TABLE1.REFNO=TABLE2.REFNO"
  20. BRDa.Execute QRY2, dbFailOnError
  21.  
  22. b = b + 1
  23. RS.MoveNext
  24. Loop
  25. TextBox1.Text = b
  26. RS.Close
  27.  
  28. BRDa.Close
  29. End If
  30. End Sub
But it doesn't work. Could someone help me pleasee... T__T!! Thank you..
Apr 12 '16 #1
5 2237
NeoPa
32,556 Expert Mod 16PB
I'm sure someone will help you, but they deserve a little more than "My code doesn't work".

Does it compile even?
Where does it fail?
What's the error message and number?

Without these basic items of a question I suspect many will look elsewhere to find something to help with.
Apr 13 '16 #2
yudia
4
Yes, I have compile my codes but it was failed and the error message : Table2 couldn't not be found in as400 database. In my opinion, since I have used inner join codes, it couldn't be placed at the same sub macro with as400 data base. Other words, combine as400 with excel data couldn't be joined by inner join codes. I need helps, whether anyone have better solutions :)
Apr 13 '16 #3
NeoPa
32,556 Expert Mod 16PB
From that error message I'd say that the JOIN type isn't the issue. It doesn't even see that [Table2] exists. Also, it wants to find it from the AS400 rather than the Excel source.

I think you probably need to set up linked tables in your database and run the SQL off that. Running it against the ADODB connection will cause that SQL to be run against that connection. No good if it wants data from Excel.
Apr 13 '16 #4
yudia
4
In MSSQL programming, there is a code : INNER JOIN OPENROWSET to join table in excel worksheet with MSSQL database.

My question is What codes in VBA Programming that have the same function as INNER JOIN OPENROWSET in MSSQL but the function is joining table in excel worksheet with AS400 database. Thanks.
Apr 14 '16 #5
NeoPa
32,556 Expert Mod 16PB
There is only one question per thread. I've already answered it. At the very least you'll have to work with a database or connection that is able to see and reference all the data you need in your query. If the AS400 can do that, then fine. I doubt that's the case but I'm no expert on your setup. The only sensible solution I can see is as in the previous response, which is to link the tables in an Access database.

If your interest is finding an equivalent of some T-SQL then you'll need to post that separately. If so, please make sure the question makes sense. It needs to include which type of SQL from and to. Asking about converting from T-SQL to VBA makes no sense as they're not comparable. One's a data manipulation language and the other's a programming language. They are not remotely compatible.
Apr 15 '16 #6

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

Similar topics

4
by: michael newport | last post by:
in Ingres I can do this update table1 from table2 set table1.field = table2.field where table1.id = table2.id is there an equivalent in Oracle ? Regards Michael Newport
1
by: Yakimo | last post by:
Hi I am trying to append some records form tmpSource to tmpDest table using datasets My setup is the following: - daSource - dataadapter for source table - daDest - dataadapter for Dest table...
3
by: Yakimo | last post by:
Hi I am trying to append some records form tmpSource to tmpDest table using datasets Tables tmpSourec and tmpDest are identical. My setup is the following: - daSource - data adapter for...
1
by: wizardRahl | last post by:
Hello all, I have a form that allows a user to add employees. I have written the code that uses the "on click" event from a button, attempting to add the employee's info into 2 tables, ...
0
by: Serenityquinn15 | last post by:
Hi! I have two Table names: tblupdate tblDetails What i want to do is to update the table tblupdate from tblDetails using the button in Visual basic Interface.
1
by: delusion7 | last post by:
Hi.. I have 2 tables: country and ticket country table contains countryId and countries ticket table contains many fields, and a country field the country table is new and consists of all...
2
by: SwigriD | last post by:
Hello all, I'm not sure how to update table form same table. I've got this code so far, which doesn't work. :-/ UPDATE WIP SET Status = WIP2.Status FROM WorkInProgress AS WIP JOIN...
6
by: Rolandas | last post by:
Hello, I have one table which I want to append it with new records, e.g. let's call this table TABLE1. The table from which I want to append is TABLE2. This table is made from queries, so it is...
2
by: Phil Siedoff | last post by:
I'm in need of taking an Excel spreadsheet that has @ 5800 records of all different zip codes. Where many zip codes belong to one sale rep but also can have a different backup sales rep. So with...
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: 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...
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?
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
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
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.