Access denied error when trying to run this script
Forums
- my ODBC connection key is correct
Sub Main
Call ODBCImport()
End Sub
Function ODBCImport()
On Error GoTo ErrHandler
' === 1. Definir nombre del archivo IDEA a crear ===
Dim dbName As String
dbName = "TGEN_SALDOMODULOS.IMD"
Dim x As String
x = "" & Chr(34) & "FISA" & Chr(34) & "." & Chr(34) & "TGEN_SALDOMODULOS" & Chr(34) & ""
' === 2. Consulta SQL para importar los datos desde ODBC ===
Dim sqlQuery As String
sqlQuery = "SELECT * FROM ( " & _
"SELECT " & _
" TGEN_SALDOMODULOS.DATELOAD, " & _
" TPRE_CUOTAS.CUO_CREDITO, " & _
" TPRE_CUOTAS.CUO_NUMCUO, " & _
" TPRE_CUOTAS.CUO_VALOR, " & _
" TPRE_CUOTAS.CUO_CAPITAL, " & _
" TPRE_CUOTAS.CUO_INTERES, " & _
" TPRE_CUOTAS.CUO_COMISION, " & _
" TPRE_CUOTAS.CUO_IMPUESTO, " & _
" TPRE_CUOTAS.CUO_CARGOS, " & _
" TPRE_CUOTAS.CUO_SEGURO, " & _
" TPRE_CUOTAS.CUO_FECHA, " & _
" TPRE_CUOTAS.CUO_FECPAG, " & _
" TPRE_PRESTAMOS.PRE_CLIENTE, " & _
" TCLI_PERSONA.CLI_IDENTIFICA, " & _
" TCLI_PERSONA.CLI_FECHNAC, " & _
" TGEN_SALDOMODULOS.ACC, " & _
" TGEN_CUENTA.PRO_NOMCTA, " & _
" TGEN_CUENTA.PRO_NOMCTA2 " & _
"FROM TPRE_CUOTAS " & _
"JOIN TPRE_PRESTAMOS ON TPRE_CUOTAS.CUO_CREDITO = TPRE_PRESTAMOS.PRE_CREDITO " & _
"JOIN TCLI_PERSONA ON TPRE_PRESTAMOS.PRE_CLIENTE = TCLI_PERSONA.CLI_IDENTIFICA " & _
"JOIN TGEN_SALDOMODULOS ON TPRE_CUOTAS.CUO_CREDITO = TGEN_SALDOMODULOS.ACC " & _
"JOIN TGEN_CUENTA ON TGEN_SALDOMODULOS.ACC = TGEN_CUENTA.PRO_CODCTA" & _
")"
' === 3. Importar los datos mediante ODBC ===
Dim odbcString As String
odbcString = ";DSN=BLH9I.world;UID=mgortiz;PWD=PWD=_IDEA922_012010062027024086039027105003094003018;DBQ=BLH9I.WORLD;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BNF=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000;TLO=O;MLD=0;ODA=F;"
' Importar base desde ODBC
Client.ImportODBCFile x, dbName, False, odbcString, sqlQuery
' === 4. Exportar base a Excel (opcional) ===
Dim exportPath As String
exportPath = "C:\IDEA\Exportaciones\Resultado.xlsx"
Client.ExportDatabase dbName, exportPath, "Excel"
MsgBox "Importación y exportación completadas correctamente.", vbInformation
Exit Function
ErrHandler:
MsgBox "Ocurrió un error: " & Err.Description, vbCritical
End Function
Hi there, For this type of…
Hi there,
For this type of error I suggest you contact support. I am not really set-up to try and figure out an error for an ODBC import.
Brian