I have a code, which runs on a button hit.
When you hit the button, it adds a path paramterers to the variable mappa, and then from that it creates a new file.
After that I'm connecting to sql, then I want to export datas based on the values of the cells. The values of the cells is given to a variable, and I want to give the sql those variables values.
I don't know if this is correct but without these lines its gives the same error, so I can't even try them out!
So on the end it gives me an error like this.
Run-time error '-2147467259 (80004005)':
Automation error
What could it mean? And how can I fix it?
Sub INDITAS3(mappa As String)
'excel.txt megnyitása
Workbooks.OpenText Filename:= _
mappa & "\excel.txt", Origin:=1250, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1)), TrailingMinusNumbers:=True
'-----csatlakozás
Dim cn As ADODB.connection
Dim strConn As String
Dim strSQL As String
Dim strXLSource As String
'kapcsolódás
strConn = strConn & "Provider=SQLOLEDB;Data Source=;"
strConn = strConn & "Initial Catolog=;Trusted_Connection=YES"
Set cn = New ADODB.connection
cn.Open "DRIVER={MySQL ODBC 5.1 Driver}" _
& ";SERVER=localhost" _
& ";DATABASE=test3" _
& ";UID=root" _
& ";PWD=root" _
& ";OPTION=16427"
strXLSource = "c:\david\NE_Arfolyam 2.xlsm;Extended Properties=Excel 12.0"
'---------
'excel.txt feldolgozása
Dim wb As Workbook
Set wb = Workbooks("excel.txt")
Dim ws As Worksheet
Set ws = wb.Sheets(1)
'ThisWorkbook.Activate 'az NE_Arfolyam excel fájl aktiválása
Dim datumido As String
datumido = ws.Range("A1").Value 'az A1 cella értékét átadjuk a datumido változónak
Dim nev, valutaneve As String
Dim i As Integer
Dim v_eladas, v_vetel As Integer
i = 2
Do While ws.Range("A" & i).Value <> "" '???addig amíg A i-edik értéke #
If ws.Range("A" & i).Value <> "***" Then 'hogyha a létrehozott excel file A oszlop +i-edik értékén *** van akkor befejezi
'1es if
If ws.Range("A" & i).Value = "#" Then 'hogyha a létrehozott excel file A oszlop +i-edik értékén # akkor megy tovább a kódban mert a fájlban # után valuták vannak
nev = ws.Range("B" & i).Value 'a megnyitott excel file B2-es mezőjében szereplő értéket a nev változónak adjuk
strSQL = "INSERT INTO arfolyam (irodanev)"
strSQL = strSQL & "VALUES ("" & nev & "")"
'1es else
Else
'konkurencia árfolyam megfelelő helyre írása
valutanev = ws.Range("A" & i).Value 'itt megkapjuk a valuta nevét
strSQL = "INSERT INTO arfolyam (valutanev)"
strSQL = strSQL & "VALUES ("" & valutaneve & "")"
v_eladas = ws.Range("B" & i).Value
strSQL = "INSERT INTO arfolyam (eladas)"
strSQL = strSQL & "VALUES ("" & v_eladas & "")"
v_vetel = ws.Range("C" & i).Value
strSQL = "INSERT INTO arfolyam (vetel)"
strSQL = strSQL & "VALUES ("" & v_vetel & "")"
End If '1es else
End If '1es if
i = i + 1
Loop
Debug.Print strSQL
cn.Execute strSQL, adExecuteNoRecords <-- IT GIVES THE ERROR HERE
End Sub
When you hit the button, it adds a path paramterers to the variable mappa, and then from that it creates a new file.
After that I'm connecting to sql, then I want to export datas based on the values of the cells. The values of the cells is given to a variable, and I want to give the sql those variables values.
I don't know if this is correct but without these lines its gives the same error, so I can't even try them out!
So on the end it gives me an error like this.
Run-time error '-2147467259 (80004005)':
Automation error
What could it mean? And how can I fix it?
Sub INDITAS3(mappa As String)
'excel.txt megnyitása
Workbooks.OpenText Filename:= _
mappa & "\excel.txt", Origin:=1250, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=True, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1)), TrailingMinusNumbers:=True
'-----csatlakozás
Dim cn As ADODB.connection
Dim strConn As String
Dim strSQL As String
Dim strXLSource As String
'kapcsolódás
strConn = strConn & "Provider=SQLOLEDB;Data Source=;"
strConn = strConn & "Initial Catolog=;Trusted_Connection=YES"
Set cn = New ADODB.connection
cn.Open "DRIVER={MySQL ODBC 5.1 Driver}" _
& ";SERVER=localhost" _
& ";DATABASE=test3" _
& ";UID=root" _
& ";PWD=root" _
& ";OPTION=16427"
strXLSource = "c:\david\NE_Arfolyam 2.xlsm;Extended Properties=Excel 12.0"
'---------
'excel.txt feldolgozása
Dim wb As Workbook
Set wb = Workbooks("excel.txt")
Dim ws As Worksheet
Set ws = wb.Sheets(1)
'ThisWorkbook.Activate 'az NE_Arfolyam excel fájl aktiválása
Dim datumido As String
datumido = ws.Range("A1").Value 'az A1 cella értékét átadjuk a datumido változónak
Dim nev, valutaneve As String
Dim i As Integer
Dim v_eladas, v_vetel As Integer
i = 2
Do While ws.Range("A" & i).Value <> "" '???addig amíg A i-edik értéke #
If ws.Range("A" & i).Value <> "***" Then 'hogyha a létrehozott excel file A oszlop +i-edik értékén *** van akkor befejezi
'1es if
If ws.Range("A" & i).Value = "#" Then 'hogyha a létrehozott excel file A oszlop +i-edik értékén # akkor megy tovább a kódban mert a fájlban # után valuták vannak
nev = ws.Range("B" & i).Value 'a megnyitott excel file B2-es mezőjében szereplő értéket a nev változónak adjuk
strSQL = "INSERT INTO arfolyam (irodanev)"
strSQL = strSQL & "VALUES ("" & nev & "")"
'1es else
Else
'konkurencia árfolyam megfelelő helyre írása
valutanev = ws.Range("A" & i).Value 'itt megkapjuk a valuta nevét
strSQL = "INSERT INTO arfolyam (valutanev)"
strSQL = strSQL & "VALUES ("" & valutaneve & "")"
v_eladas = ws.Range("B" & i).Value
strSQL = "INSERT INTO arfolyam (eladas)"
strSQL = strSQL & "VALUES ("" & v_eladas & "")"
v_vetel = ws.Range("C" & i).Value
strSQL = "INSERT INTO arfolyam (vetel)"
strSQL = strSQL & "VALUES ("" & v_vetel & "")"
End If '1es else
End If '1es if
i = i + 1
Loop
Debug.Print strSQL
cn.Execute strSQL, adExecuteNoRecords <-- IT GIVES THE ERROR HERE
End Sub
Last edited: