Hello everyone,
I have a .csv file that needs to be imported into a IBM DB2 table. I can import .csv data manually, but I want to do It automatically with VBA, If possible.
I have found some VBA code that might work, but cannot set It right, or It isn't what I think It is.
Code:
Option Explicit
Dim DBCONSRT, QRYSTR ans As String
Dim DBCON, DBRS As Object
Dim excel_app As Object
Private Sub CommandButton1_Click()
Set excel_app = CreateObject("Excel.Application")
DBCONSRT = "Driver={IBM DB2 ODBC DRIVER};Database=<OFFROAD>;hostname=<localhost>;port=<50000;protocol=TCPIP; uid=<db2admin>; pwd=<sample123>"
'CHANGE THE BELOW QUERY STRING ACCORDIGN TO YOUR NEED
QRYSTR = "db2 import from C:\Users\db2admin.Luka-PC\Documents\auth.csv of del insert into db2admin.razpored"
Set DBCON = CreateObject("ADODB.Connection")
DBCON.ConnectionString = DBCONSRT
DBCON.Open
'BELOW CODE USED TO GET THE DATABASE CONECTION AND EXECUTE THE QUERY CHANGE ACCORDIGN TO YOUR NEED
Set DBRS = CreateObject("ADODB.Recordset")
With DBRS
.Source = QRYSTR
Set .ActiveConnection = DBCON
.Open
End With
End Sub
When I run the code I get an error "[IBM][CLI driver] SQL1337N The service "<50000>" was not found" !
I don't know about OLE DB or ODBC driver - as instructed, I should have one installed on local machine, but can't find anywhere how to download It.
Also, when I use Data>Import External data>Import Data tool in Excel, I can connect to DB2 database directly from Excel, so maybe ODBC driver allready installed ??
My version of DB2 is Express-C 10.5, and Excel 2003.
I'm not sure either If red coloured line of code is basically an SQL command or db2cmd command (which I need exactly as written - I need to import .csv into specific table called "razpored")
I know this is probably a tough question, but can somebody please help me ?
Bookmarks