I want to update table in as400 using table in excel worksheet like this :
Table1 [as400] - REFNO I QTY
-
1 I 10
-
2 I 12
-
3 I 20
Table2 [excel worksheet] - REFNO I QTY
-
1 I 13
-
2 I 15
-
3 I 22
Qty in Table1 updated from Table2 using VBA so the ouput will be like this : - Table1 [as400]
-
REFNO I QTY
-
1 I 13
-
2 I 15
-
3 I 22
I have used inner join code like this : - Dim s1 As Worksheet
-
Dim BRDa As ADODB.Connection
-
Dim RS As ADODB.Recordset
-
Dim b As Integer
-
-
Set RS = New ADODB.Recordset
-
Set BRDa = New ADODB.Connection
-
BRDa.ConnectionString = "provider=ABC; Data source=XYZ; user id=OK1; password=OK2"
-
BRDa.Open
-
-
On Error Resume Next
-
Dim QRY1, QRY2 As String
-
QRY1 = "SELECT * FROM TABLE1 INNER JOIN S1.TABLE2 ON TABLE1.REFNO=TABLE2.REFNO"
-
RS.Open QRY1, BRDa, adOpenDynamic, adLockOptimistic
-
-
b = 0
-
-
Do While Not RS.EOF
-
QRY2 = "UPDATE TABLE1 SET TABLE1.QTY = TABLE2.QTY WHERE TABLE1.REFNO=TABLE2.REFNO"
-
BRDa.Execute QRY2, dbFailOnError
-
-
b = b + 1
-
RS.MoveNext
-
Loop
-
TextBox1.Text = b
-
RS.Close
-
-
BRDa.Close
-
End If
-
End Sub
But it doesn't work. Could someone help me pleasee... T__T!! Thank you..
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.
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 :)
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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...
|
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, ...
|
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.
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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: 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...
|
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...
| |