VBA multi-line string questions

I don't have much experience writing a VBA script, I almost lost to learn in a multi-line string. Where exactly am I lost when I try to split String into several lines, could you help me how to finish

The working line is below before splitting:

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 & "'" & ")"

Doesn’t work below, I try to split the rows because I have many columns to include in the insert, and it is more than 1000 characters and cannot fit on one line (below is just a sample, the actual one is much longer, and I am forced to split the rows).

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 got confused, thanks

+4
source share
3 answers

You need to run the following 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 & "'" & ")"

, , "&". . :

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 & "')"

. , "vbCrLf" SQL. .

+8

vbCrLf , .

:

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 & "'" & ")"
0

I tried with this option after I launched another post and worked, thanks for the proof of other solutions, rate it.

 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 & "'" & ")"
0
source

All Articles