Paste Workbook.Queries into arrays without pasting to sheet - excel

So I have a bit of a problem with some query connections that I want to deal with inside an array because they can hold more rows than Excel can handle.
Option Explicit
Sub RefrescaConsultas()
EliminaConsultas
CreaConsultas
End Sub
Private Sub EliminaConsultas()
Dim Consulta As Object
For Each Consulta In ThisWorkbook.Queries
Consulta.Delete
Next Consulta
End Sub
Private Sub CreaConsultas()
Dim Mes As String: Mes = HMacro.Range("B2")
Dim Año As Long: Año = HMacro.Range("B1")
Dim MesNum As Byte: MesNum = Month(DateValue("01/" & Mes & "/2020"))
Dim RutaAccess As String: RutaAccess = Chr(34) & "\\ate2899cor01\reporting_administrativos\TELEFONICA\GP\Informe Evolucion Territorios\2020\Modelo Marzo´20\Inforrme Evolucion Ventas\Nuevo informe\BBDD\Actualiza Conversores.accdb" & Chr(34)
'Brutas
ThisWorkbook.Queries.Add "Brutas", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Brutas = Origen{[Schema="""",Item=""Brutas""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Rem" & _
"oveColumns(_Brutas,{""fx_proceso"", ""fx_estado_fin"", ""fx_devengo"", ""estado"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""faro"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", " & _
"""telefono"", ""segmento"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""producto_comision_alta_comercial"", ""producto_comision_actualizad" & _
"o"", ""importe_comision"", ""COD_T9"", ""rf_tq"", ""operacion"", ""sub_producto_destino_alta_comercial"", ""num_lineas_movil_tipo_fusion"", ""num_lineas_movil_planta"", ""in_fusion"", ""anul_15"", ""anul_30"", ""anul_60"", ""co_resolucion_sia"", ""resolucion_sia"", ""causa_anulacion"", ""fuente_origen"", ""cliente_nuevo"", ""in_servicio_tv""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Dat" & _
"e.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'TV
ThisWorkbook.Queries.Add "TV", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _TV = Origen{[Schema="""",Item=""TV""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.RemoveColum" & _
"ns(_TV,{""fx_proceso"", ""fx_estado_fin"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provincia_cliente"", ""ccaa_cli" & _
"ente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""no_sucursal"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""baja_prematura"", ""dias_baja"", ""producto_comision_alta_comercial"", ""importe_comision"", ""COD_T9"", ""rf_tq"", ""nu_administra"", ""fuente" & _
"_origen"", ""ds_fusion_origen"", ""ds_fusion_destino"", ""baja_prematura_8_mes_sig"", ""IN_PLANTA_8_MES_SIG"", ""CLIENTE_NUEVO""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Fusion
ThisWorkbook.Queries.Add "Fusion", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Fusion = Origen{[Schema="""",Item=""Fusion""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Rem" & _
"oveColumns(_Fusion,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""fx_instalacion"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""telefono"", ""segmento"", ""provincia" & _
"_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""matricula_origen"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""baja_prematura"", ""producto_comision_alta_comercial"", ""COD_T9"", ""valor_origen"", ""valor_destino"", ""rf_tq"", " & _
"""dif_dias_baja"", ""in_servicio_tv_origen"", ""in_servicio_tv_destino"", ""num_lineas_movil_tipo_fusion"", ""num_lineas_movil_planta"", ""CUC"", ""fuente_origen"", ""fx_alta_desco""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Inserciones
ThisWorkbook.Queries.Add "Inserciones", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Inserciones = Origen{[Schema="""",Item=""Inserciones""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" =" & _
" Table.RemoveColumns(_Inserciones,{""fx_proceso"", ""fx_estado_fin"", ""estado"", ""causa_estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""indicador_negocio_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provi" & _
"ncia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""cod_comision_alta_comercial"", ""producto_comision_alta_comercial"", ""importe_comision"", ""co_contrato"", ""co_plantari"", ""operado" & _
"r_origen"", ""operador_destino"", ""ICC"", ""LIQUIDABLE"", ""TARJETA_VIRTUAL"", ""NUMERO_REPETICIONES"", ""FUENTE_ORIGEN""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Prosegur
ThisWorkbook.Queries.Add "Prosegur", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Prosegur = Origen{[Schema="""",Item=""Prosegur""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table" & _
".RemoveColumns(_Prosegur,{""fx_proceso"", ""fx_estado_fin"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_solicitado"", ""indicador_negocio_solicitado"", ""producto_solicitado"", ""sub_producto_destino_solicitado"", ""subproducto_origen_solicitado"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_a" & _
"lta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""CUC"", ""tipo_doc"", ""id_fiscal"", ""telefono"", ""segmento"", ""localidad_cliente"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""matricula_origen"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta" & _
""", ""ccaa_venta"", ""territorio_venta"", ""pais_vendedor"", ""FechaGrab"", ""FechaGrabInci"", ""in_fusion"", ""tipo"", ""nu_administra"", ""unidades"", ""id_senializacion"", ""cod_comision_solicitado"", ""producto_comision_solicitado"", ""producto_comision_alta_comercial"", ""id_lead"", ""COD_T9"", ""rf_tq"", ""producto_comision_actualizado"", ""fuente_origen"", """ & _
"co_unico"", ""fecha_compromiso_ini"", ""fecha_alta_sistema"", ""Campo61"", ""Campo62"", ""Campo63""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_solicitud]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Repos Móvil
ThisWorkbook.Queries.Add "Repos", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Repos = Origen{[Schema="""",Item=""Repos""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Remov" & _
"eColumns(_Repos,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_solicitado"", ""indicador_negocio_solicitado"", ""sub_producto_origen_alta_comercial"", ""subproducto_origen_alta_comercial"", ""cod_indicador_negocio_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_destino_alta_comercial"", " & _
"""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""localidad_cliente"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""matricula_origen"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""pais_vendedor" & _
""", ""in_fusion"", ""tipo"", ""operador_origen"", ""operador_destino"", ""in_terminal"", ""FechaGrab"", ""FechaGrabInci"", ""co_contrato_origen"", ""co_contrato_destino"", ""co_plantari_origen"", ""co_plantari_destino"", ""cod_comision_solicitado"", ""producto_comision_solicitado"", ""producto_comision_alta_comercial"", ""ICC"", ""FUENTE_ORIGEN"", ""Arpu_Origen"", " & _
"""Arpu_Destino"", ""unidades""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Terminales
ThisWorkbook.Queries.Add "Terminales", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Terminales = Origen{[Schema="""",Item=""Terminales""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = T" & _
"able.RemoveColumns(_Terminales,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""producto_alta_comercial"", ""sub_producto_destino_alta_comercial"", ""subproducto_origen_alta_comercial"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provinci" & _
"a_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", ""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""producto_comision_alta_comercial"", ""importe_comision"", ""vendedor_entrega"", ""canal_venta_entrega"", ""agrupacion_canal_entrega"", """ & _
"canal_entrega"", ""detalle_canal_entrega"", ""co_proveedor_entrega"", ""no_empresa_entrega"", ""co_centro_venta_entrega"", ""no_sucursal_entrega"", ""provincia_venta_entrega"", ""territorio_venta_entrega"", ""tipo"", ""gama_terminal"", ""in_financiado"", ""nu_imei"", ""cod_campania"", ""FUENTE_ORIGEN"", ""Campo56"", ""Campo57"", ""Campo58"", ""Campo59"", ""Campo60""" & _
", ""Campo61""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'Móvil
ThisWorkbook.Queries.Add "Movil", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _Movil = Origen{[Schema="""",Item=""Movil""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.Remov" & _
"eColumns(_Movil,{""fx_proceso"", ""fx_solicitud"", ""fx_devengo"", ""estado"", ""operacion"", ""cod_indicador_negocio_alta_comercial"", ""subproducto_origen_alta_comercial"", ""co_modven"", ""soporte"", ""codigo_pedido"", ""tipo_doc"", ""id_fiscal"", ""CUC"", ""telefono"", ""segmento"", ""provincia_cliente"", ""ccaa_cliente"", ""territorio_cliente"", ""vendedor"", " & _
"""canal_venta"", ""co_proveedor"", ""no_empresa"", ""co_centro_venta"", ""provincia_venta"", ""ccaa_venta"", ""territorio_venta"", ""FechaGrab"", ""unidades"", ""baja_prematura"", ""dif_dias_baja"", ""producto_comision_alta_comercial"", ""importe_comision"", ""in_terminal"", ""co_contrato"", ""co_plantari"", ""operador_origen"", ""operador_destino"", ""ICC"", ""fuen" & _
"te_origen""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each Date.Month([fx_estado_fin]) = " & MesNum & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas"""
'TMO
ThisWorkbook.Queries.Add "TMO", "let" & Chr(13) & "" & Chr(10) & " Origen = Access.Database(File.Contents(" & RutaAccess & "), [CreateNavigationProperties=true])," & Chr(13) & "" & Chr(10) & " _TMO = Origen{[Schema="""",Item=""TMO""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Columnas quitadas"" = Table.RemoveCol" & _
"umns(_TMO,{""semana"", ""New_Territorio"", ""PAIS_TABLA"", ""MODO TABLA"", ""MODO TABLA TMO"", ""FX_LLAMADA"", ""NO_SEGMENTO"", ""NO_TERRITORIO"", ""NO_SUBTERRITORIO"", ""NO_PROVEEDOR"", ""NO_ORIGEN"", ""Terri_cliente"", ""Subterri_cliente"", ""ORIGEN"", ""NO_SEGMENTO_SKILL"", ""CO_GRABACION"", ""CLIENTE_NUEVO"", ""DS_SEGMENTO_ORGANIZATIVO"", ""B2C"", ""Idioma"", """ & _
"CO_TIPO_EMISION"", ""IN_AGENDADA"", ""CA_RECIBIDAS"", ""CA_LLAMADAA_VALIDAA"", ""CA_Atendidas_Entrantes"", ""CA_Aten_20seg"", ""CA_Conv_M20Seg"", ""CA_TMO"", ""CA_TMO_S"", ""CA_TME"", ""CA_Tr_Imputables"", ""CA_Transferidas"", ""CA_Salientes"", ""CA_AGENDADAS"", ""CA_TMO_AGENDADAS""})," & Chr(13) & "" & Chr(10) & " #""Filas filtradas"" = Table.SelectRows(#""Columnas quitadas"", each [Mes] =" & _
MesNum & ")," & Chr(13) & "" & Chr(10) & " #""Filas filtradas1"" = Table.SelectRows(#""Filas filtradas"", each [Año] = " & Año & ")" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filas filtradas1"""
End Sub
The code is fairly simple, I've manually recorded Data->from data base->selected the data base->deleted some columns for each connection and filtered some data.
Now the workbook has all these connections that I need to work with, but pasting them into a sheet and then into an array might be a problem because some of them are more than 1M rows... Any Insight on how to achieve this?

Specifications and Limits for Excel Worksheets and Workbooks
Total number of rows and columns in a worksheet :
1,048,576 rows and 16,384 columns
so you may have to add a clause to limit the number of rows: select TOP 1000 in your SQL request
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Customer;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT TOP 10OO fx_proceso FROM [Prosegur]")

Related

How to update Source ID in ActiveWorkbook.Queries.Add

I'm trying to add parameters into a ActiveWorkbook.Queries.Add
I have managed to change all except the on in 'Source{[Id=""Table001""]}', inside the ActiveWorkbook.Queries.Add
I have tried Source{[Id=" & TableOnly & "]} but I get an error in line 'ActiveWorkbook.Queries.Add': The import table Table001 matches no exports
See below the full code and where 'Source{[Id=""Table001""]}' is located
For i = 1 to 3
TableName = "Table00" & i & " (Page " & i + 2 & ")" 'Example: "Table001 (Page 3)"
DispName = "Table00" & i & "__Page_" & i + 2 & "" 'Example: "Table001__Page_3"
TableOnly = "Table00" & i 'Example: Table001
ActiveWorkbook.Queries.Add Name:=TableName, Formula:= _
"let" & Chr(13) & "" & Chr(10) & _
" Source = Pdf.Tables(File.Contents(""C:\Sample.pdf""), [Implementation=""1.3""])," & Chr(13) & "" & Chr(10) & _
" " & TableOnly & " = Source{[Id=""Table001""]}[Data]," & Chr(13) & "" & Chr(10) & _
" #""Changed Type"" = Table.TransformColumnTypes(" & TableOnly & ",{{""Column1"", type text}, {""Column2"", type text}, {""Column3"", type text}, {""Column4"", type text}, {""Column5"", " & _
"type text}, {""Column6"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=" & TableName & ";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [" & TableName & "]")
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = DispName
.Refresh BackgroundQuery:=False
End With
Next
I found the problem. I had to add an addition inverted comas at each end as:
Source{[Id=""" & TableOnly & """]}
Hope is helps someone.

Having a Token Error when creating PowerQuery

This sub creates a powerquery with the source from a folderpath, it gets all the excel files from the folder and consolidate and filter it.
I am having an error whenever I make Source = Folder.Files("Dir") dynamic
Is there a way to make the paths dynamic so that I will just refresh the query page and update the value of the SourcePath for Folder.Files in my Settings sheet.
I have this error
Runtime-error '1004':
[Expression.Error] The name 'Source' wasn't recognized, Make sure it's spelled correctly.
in this line .Refresh BackgroundQuery:=False
If I create a value for SourcePath referencing a cell in a sheet with this format "C:\Path" ,It has this error
Error:
Runtime Error '1004':
Application Defined or Object-defined error
in this line
.ListObject.DisplayName = "Data"
Sub AddSaveQuery()
'Set Objects
Dim SourcePath As String
Dim SavePath As String
SourcePath = Worksheets("Home").Range("G21").Value
SavePath = Worksheets("Home").Range("G8").Value
Sub AddSaveQuery()
'Set Objects
Dim SourcePath As String
Dim SavePath As String
SourcePath = Worksheets("Home").Range("G21").Value
SavePath = Worksheets("Home").Range("G8").Value
'Will set first condition for sheet2
'Filter Column2 Begins with FilterValue1
ActiveWorkbook.Queries.Add Name:="Data", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Folder.Files(""" & SourcePath & """)," & Chr(13) & "" & Chr(10) & " #""Filtered Hidden Files1"" = Table.SelectRows(Source, Each [Attributes]?[Hidden]? <> true)," & Chr(13) & "" & Chr(10) & " #""Invoke Custom Function1"" = Table.AddColumn(#""Filtered Hidden Files1"", ""Transform File"", Each #""Transform File""([Content]))," & Chr(13) & "" & Chr(10) & " #""Renamed Columns1""" & _
" = Table.RenameColumns(#""Invoke Custom Function1"", {""Name"", ""Source.Name""})," & Chr(13) & "" & Chr(10) & " #""Removed Other Columns1"" = Table.SelectColumns(#""Renamed Columns1"", {""Source.Name"", ""Transform File""})," & Chr(13) & "" & Chr(10) & " #""Expanded Table Column1"" = Table.ExpandTableColumn(#""Removed Other Columns1"", ""Transform File"", Table.ColumnNames(#""Transform File""(#""Sample File"")))," & Chr(13) & "" & _
"" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(#""Expanded Table Column1"",{{""Source.Name"", Type text}, {""Column1"", Type any}, {""Column2"", Type any})," & Chr(13) & "" & Chr(10) & " #""Removed Other Columns"" = Table.SelectColumns(#""Column1" & _
"ed Type"",{""Column2""})," & Chr(13) & "" & Chr(10) & " #""Filtered Rows"" = Table.Sel" & _
"ectRows(#""Removed Other Columns"", Each Text.StartsWith([Column2], ""FilterValue1""))" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Filtered Rows"""
ActiveWorkbook.Queries.Add Name:="Parameter1", Formula:= _
"#""Sample File"" meta [IsParameterQuery=true, BinaryIdentifier=#""Sample File"", Type=""Binary"", IsParameterQueryRequired=true]"
ActiveWorkbook.Queries.Add Name:="Transform Sample File", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Excel.Workbook(Parameter1, null, true)," & Chr(13) & "" & Chr(10) & " Page1_Sheet = Source{[Item=""Page1"",Kind=""Sheet""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Promoted Headers"" = Table.PromoteHeaders(Page1_Sheet, [PromoteAllScalars=true])" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Promoted Headers"""
ActiveWorkbook.Queries.Add Name:="Sample File", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Folder.Files(""" & SourcePath & """)," & Chr(13) & "" & Chr(10) & " Navigation1 = Source{0}[Content]" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Navigation1"
ActiveWorkbook.Queries.Add Name:="Transform File", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = (Parameter1) => let" & Chr(13) & "" & Chr(10) & " Source = Excel.Workbook(Parameter1, null, true)," & Chr(13) & "" & Chr(10) & " Page1_Sheet = Source{[Item=""Page1"",Kind=""Sheet""]}[Data]," & Chr(13) & "" & Chr(10) & " #""Promoted Headers"" = Table.PromoteHeaders(Page1_Sheet, [PromoteAllScalars=true])" & Chr(13) & "" & Chr(10) & " in" & Chr(13) & "" & Chr(10) & " #""Promoted Headers""" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " Source"
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Data;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Data]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Data"
.Refresh BackgroundQuery:=False
End With
Workbooks("CognosDataCleaner2.xlsm").Connections.Add2 "Query - Parameter1", _
"Connection To the 'Parameter1' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Parameter1;Extended Properties=""""" _
, "SELECT * FROM [Parameter1]", 2
Workbooks("CognosDataCleaner2.xlsm").Connections.Add2 _
"Query - Transform Sample File", _
"Connection To the 'Transform Sample File' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Transform Sample File"";Extended Properties=""""" _
, "SELECT * FROM [Transform Sample File]", 2
Workbooks("CognosDataCleaner2.xlsm").Connections.Add2 "Query - Sample File", _
"Connection To the 'Sample File' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Sample File"";Extended Properties=""""" _
, "SELECT * FROM [Sample File]", 2
Workbooks("CognosDataCleaner2.xlsm").Connections.Add2 "Query - Transform File" _
, "Connection To the 'Transform File' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Transform File"";Extended Properties=""""" _
, "SELECT * FROM [Transform File]", 2
'Rename New Query Sheet to TEST1
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "TEST1"
Sheets("TEST1").Select
Workbooks("Book1").Connections.Add2 "Query - Transform File", _
"Connection To the 'Transform File' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Transform File"";Extended Properties=""""" _
, "SELECT * FROM [Transform File]", 2
Workbooks("Book1").Connections.Add2 "Query - Sample File", _
"Connection To the 'Sample File' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Sample File"";Extended Properties=""""" _
, "SELECT * FROM [Sample File]", 2
Sheets("TEST1").Copy
'SAVE PATH
ChDir SavePath
ActiveWorkbook.SaveAs Filename:= _
SavePath _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
End Sub
I have created an Object SourcePath and in that path I concat it so it does have the value like this:
"Directory"
A1 = "
A2 = "
A3 = Directory or path
=CONCAT(A1 & A3 & A2)
I also have set Source as String to make it an object aswell.
You need quotes round the path, so:
"let" & Chr(13) & "" & Chr(10) & " Source = Folder.Files(""" & SourcePath & """),"

VBA QueryTables not working with Yahoo Finance

I'm trying this simple Sub (in Excel 2019) to import tables from a specific Yahoo Finance page.
It works with other websites, but with Yahoo Finance, I keep getting the same message "This Web query returned no data. To change..........." and no data is extracted.
I couldn't figure out the reason.
Sub ImportTable()
Dim ws As Worksheet
Dim qt As QueryTable
Dim qurl As String
qurl = "https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT"
Set ws = worksheets.Add
Set qt = ws.QueryTables.Add( _
Connection:="URL;" & qurl, _
Destination:=Range("A1"))
With qt
.RefreshOnFileOpen = False
.Name = "test"
.WebFormatting = xlWebFormattingNone
.WebSelectionType = xlAllTables
.Refresh
End With
End Sub
You can instead set-up connections to the various tables which will add them to the data model (Alt + B + M). In the queries pane of data you can then chose where to load them to your workbook if you wish to see them. You can also just work with them in the data model and generate your final desired output.
Note:
The quicker way is, from ribbon, to do, data > from web > enter url > select tables of interest. This will set-up table connections without vba.
VBA:
Option Explicit
Public Sub AddYahooFinanceTableConnections()
Dim wb As ThisWorkbook
Set wb = ThisWorkbook
wb.Queries.Add Name:="Balance Sheet", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data10 = Source{10}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data10,{{""Total Cash (mrq)"", type text}, {""131.99B"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Cash Flow Statement", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data11 = Source{11}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data11,{{""Column1"", type text}, {""Column2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Dividends & Splits", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data5 = Source{5}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data5,{{""Forward Annual Dividend Rate"", type text}, {""2.24"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Fiscal Year", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data6 = Source{6}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data6,{{""Column1"", type text}, {""Column2"", type date}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Income Statement", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data9 = Source{9}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data9,{{""Revenue (ttm)"", type text}, {""153.28B"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="People Also Watch", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data12 = Source{12}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data12,{{""Symbol"", type text}, {""Last Price"", type number}, {""Change"", type number}, {""% Change"", Percentage.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Profitability", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data7 = Source{7}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data7,{{""Column1"", type text}, {""Column2"", Percentage.Type}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Share Statistics", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data4 = Source{4}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data4,{{""Avg Vol (3 month)"", type text}, {""30.36M"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Stock Price History", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data3 = Source{3}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data3,{{""Beta (5Y Monthly)"", type text}, {""0.79"", type number}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Table 0", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data0 = Source{0}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data0,{{""Column1"", type text}, {""Column2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Queries.Add Name:="Table 1", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Web.Page(Web.Contents(""https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT""))," & Chr(13) & "" & Chr(10) & " Data1 = Source{1}[Data]," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Data1,{{""Column1"", type text}, {""Column2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type"""
wb.Connections.Add2 "Query - Balance Sheet", _
"Connection to the 'Balance Sheet' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Balance Sheet;Extended Properties=" _
, """Balance Sheet""", 6, True, False
wb.Connections.Add2 "Query - Cash Flow Statement", _
"Connection to the 'Cash Flow Statement' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Cash Flow Statement;Extended Properties=" _
, """Cash Flow Statement""", 6, True, False
wb.Connections.Add2 "Query - Dividends & Splits", _
"Connection to the 'Dividends & Splits' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Dividends & Splits;Extended Properties=" _
, """Dividends & Splits""", 6, True, False
wb.Connections.Add2 "Query - Fiscal Year", _
"Connection to the 'Fiscal Year' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Fiscal Year;Extended Properties=" _
, """Fiscal Year""", 6, True, False
wb.Connections.Add2 "Query - Income Statement", _
"Connection to the 'Income Statement' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Income Statement;Extended Properties=" _
, """Income Statement""", 6, True, False
wb.Connections.Add2 "Query - People Also Watch", _
"Connection to the 'People Also Watch' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=People Also Watch;Extended Properties=" _
, """People Also Watch""", 6, True, False
wb.Connections.Add2 "Query - Profitability", _
"Connection to the 'Profitability' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Profitability;Extended Properties=" _
, """Profitability""", 6, True, False
wb.Connections.Add2 "Query - Share Statistics", _
"Connection to the 'Share Statistics' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Share Statistics;Extended Properties=" _
, """Share Statistics""", 6, True, False
wb.Connections.Add2 "Query - Stock Price History", _
"Connection to the 'Stock Price History' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Stock Price History;Extended Properties=" _
, """Stock Price History""", 6, True, False
wb.Connections.Add2 "Query - Table 0", _
"Connection to the 'Table 0' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table 0;Extended Properties=" _
, """Table 0""", 6, True, False
wb.Connections.Add2 "Query - Table 1", _
"Connection to the 'Table 1' query in the workbook.", _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table 1;Extended Properties=" _
, """Table 1""", 6, True, False
End Sub

Send email to various addresses from cells

I have in "Sheet1" numerous email addresses, in columns K, M, O, Q, S, U, W, Y, AA.
I want to create an email that will be sent to all the addresses taken from the last row in Sheet1. Same for data in email body taken from last row.
Dim MonOutlook As Object
Dim MonMessage As Object
Dim EmailTo As String
With Worksheets("Sheet1")
EmailTo = .Range("K" & ligne) & ";" & .Range("M" & ligne) & ";" & .Range("O" & ligne) & ";" & .Range("Q" & ligne) & ";" & .Range("S" & ligne) & ";" & .Range("U" & ligne) & ";" & .Range("W" & ligne) & ";" & .Range("Y" & ligne) & ";" & .Range("AA" & ligne)
End With
Set MonOutlook = CreateObject("Outlook.Application")
Set MonMessage = MonOutlook.CreateItem(0)
MonMessage.To = ""
MonMessage.Cc = ""
MonMessage.Bcc = EmailTo
MonMessage.Subject = "Rate request" & " " & "for" & " " & ThisWorkbook.Sheets("Sheet1").Range("B" & ligne)
MonMessage.body = "Hello,"
Chr (13) & Chr(13) & "Please send me rate for" & " " & ThisWorkbook.Sheets("Sheet1").Range("G" & ligne) & " " & "rooms on basis" & " " & ThisWorkbook.Sheets("Sheet1").Range("H" & ligne) & _
Chr(13) & Chr(13) & "in hotel:" & " " & ThisWorkbook.Sheets("Sheet1").Range("J" & ligne) & _
Chr(13) & Chr(13) & "for the period" & " " & ThisWorkbook.Sheets("suivi").Range("C" & ligne) & " " & ThisWorkbook.Sheets("Sheet1").Range("D" & ligne) & _
Chr(13) & Chr(13) & "Thank you!" & _
Chr(13) & Chr(13) & Application.UserName & " " & "-" & " " & "x Tours"
MonMessage.Display
With ThisWorkbook.Sheets("Sheet1").Range("AB" & ligne)
.Value = Date
.NumberFormat = "dd/mm/yyyy"
End With
ActiveWorkbook.Save
Try the code below, explanations inside the code's comments.
Option Explicit
Sub EmailContactsLastRow()
Dim MonOutlook As Object
Dim MonMessage As Object
Dim EmailSht As Worksheet
Dim EmailTo As String
Dim ligne As Long
' set the worksheet object
Set EmailSht = ThisWorkbook.Sheets("Sheet1")
With EmailSht
ligne = .Cells(.Rows.Count, "K").End(xlUp).Row ' get last row with data in column K
EmailTo = .Range("K" & ligne) & ";" & .Range("M" & ligne) & ";" & .Range("O" & ligne) & ";" & _
.Range("Q" & ligne) & ";" & .Range("S" & ligne) & ";" & .Range("U" & ligne) & ";" & _
.Range("W" & ligne) & ";" & .Range("Y" & ligne) & ";" & .Range("AA" & ligne)
End With
Set MonOutlook = CreateObject("Outlook.Application")
Set MonMessage = MonOutlook.CreateItem(0)
With MonMessage
.To = ""
.Cc = ""
.Bcc = EmailTo
.Subject = "Rate request" & " " & "for" & " " & EmailSht.Range("B" & ligne)
.body = "Hello,"
Chr (13) & Chr(13) & "Please send me rate for" & " " & EmailSht.Range("G" & ligne) & " " & "rooms on basis" & " " & EmailSht.Range("H" & ligne) & _
Chr(13) & Chr(13) & "in hotel:" & " " & EmailSht.Range("J" & ligne) & _
Chr(13) & Chr(13) & "for the period" & " " & EmailSht.Range("C" & ligne) & " " & EmailSht.Range("D" & ligne) & _
Chr(13) & Chr(13) & "Thank you!" & _
Chr(13) & Chr(13) & Application.UserName & " " & "-" & " " & "x Tours"
.Display ' <-- this displays the email. not sending it
.send ' <-- this sends the email out
End With
With EmailSht.Range("AB" & ligne)
.Value = Date
.NumberFormat = "dd/mm/yyyy"
End With
ThisWorkbook.Save
End Sub

VBA Multiline String Issues

I am not having much experience writing VBA script, I am almost lost to find out in the multiline string. Where exactly I am lost is when I try to split the String in multiple lines, could you help me how to end
Working String is below before split:
strSQL = "insert into ded_limit_analysis (PDPD_ID,PDDS_DESC,PRODUCT_CAT,BASE_PDPD_ID,PROD_CYCLE,HMO_IND_DED) " & vbCrLf & _
"values (" & "'" & Me.txt_pdpd_id & "'" & "," & "'" & Me.txt_pdds & "'" & "," & "'" & Me.cbx_prod_type & "'" & "," & "'" & Me.txt_base_pdpd & "'" & "," & "'" & Me.cbx_prod_cycle & "'" & "," & "'" & Me.txt_hmo_ind_ded & "'" & ")"
The one not working is below, I am trying to split the lines because I have many columns to include in insert and it is more than 1000 caracters and not able to fit in single line (below is just sample, actual is much longer and I am forced to split the lines).
strSQL = "insert into ded_limit_analysis (PDPD_ID,PDDS_DESC,PRODUCT_CAT,BASE_PDPD_ID,PROD_CYCLE,HMO_IND_DED) " & vbCrLf & _
"values (" & "'" & Me.txt_pdpd_id & "'" & "," & "'" & Me.txt_pdds & "'" & "," & "'" & Me.cbx_prod_type & "'" & "," & "'" & Me.txt_base_pdpd & "'" & "," & "'" & Me.cbx_prod_cycle & "'" & "," & " & vbCrLf &" _
& "'" & Me.txt_hmo_ind_ded & "'" & ")"
Please advice where I am messing up, thanks
You need to start the next line with "&"
So:
strSQL = "insert into ded_limit_analysis (PDPD_ID,PDDS_DESC,PRODUCT_CAT,BASE_PDPD_ID,PROD_CYCLE,HMO_IND_DED) " _
& vbCrLf & "values (" & "'" & Me.txt_pdpd_id & "'" & "," _
& "'" & Me.txt_pdds & "'" & "," & "'" & Me.cbx_prod_type _
& "'" & "," & "'" & Me.txt_base_pdpd & "'" & "," & "'" _
& Me.cbx_prod_cycle & "'" & "," & vbCrLf _
& "'" & Me.txt_hmo_ind_ded & "'" & ")"
Although, looking at the string, you can eliminate a lot of the "&" in your code. This would be cleaner:
strSQL = "insert into ded_limit_analysis (PDPD_ID, " _
& "PDDS_DESC, " _
& "PRODUCT_CAT, " _
& "BASE_PDPD_ID, " _
& "PROD_CYCLE, " _
& "HMO_IND_DED) " _
& " values ('" & Me.txt_pdpd_id & "', '" _
& Me.txt_pdds & "', '" _
& Me.cbx_prod_type & "', '" _
& Me.txt_base_pdpd & "', '" _
& Me.cbx_prod_cycle & "', '" _
& Me.txt_hmo_ind_ded & "')"
It's just much easier to understand this way. Also, you don't need "vbCrLf" in your SQL. It's just white space.
On the second string vbCrLf is within quotes and is seen as a string rather than a command.
Try this code in place of the problem line above:
strSQL = "insert into ded_limit_analysis (PDPD_ID,PDDS_DESC,PRODUCT_CAT,BASE_PDPD_ID,PROD_CYCLE,HMO_IND_DED) " & vbCrLf & _
"values (" & "'" & Me.txt_pdpd_id & "'" & "," & "'" & Me.txt_pdds & "'" & "," & "'" & Me.cbx_prod_type & "'" & "," & "'" & Me.txt_base_pdpd & "'" & "," & "'" & Me.cbx_prod_cycle & "'" & "," & vbCrLf _
& "'" & Me.txt_hmo_ind_ded & "'" & ")"
I tried with this option after seraching other post and works, thanks for proving other solutions, appreciate that.
strSQL = "insert into ded_limit_analysis (PDPD_ID,PDDS_DESC,PRODUCT_CAT,BASE_PDPD_ID,PROD_CYCLE,HMO_IND_DED) " & vbCrLf & _
"values (" & "'" & Me.txt_pdpd_id & "'" & "," & "'" & Me.txt_pdds & "'" & "," & "'" & Me.cbx_prod_type & "'" & "," & "'" & Me.txt_base_pdpd & "'" & "," & "'" & Me.cbx_prod_cycle & "'" & ","
strSQL = strSQL & "'" & Me.txt_hmo_ind_ded & "'" & ")"

Resources