0

I'm trying to do line continuation on vb and i getting an error, here is my code

sql = "Insert into RECRUITMENT values (" JobID ",'"Department"', "Employment_Level",'"Line_Manager"', '"New_vacancy_or_Replacement"', '"Recruiter"','"Position_Status"', '"Recruitment_Stage"', '"Region"', '"Minimum_Required_Qualification"' ,'"City_or_Town"',"Date_RFS_Issued"," & "Date_of_Final_RFS_Sign_or_HC_Approval","&_
"Date_Advertised","Date_of_Capture","Return_Date","Date_Shortlist_Sent_to_LineManager","Date_Put_on_Hold","Date_For_1st_Interview","Date_For_2nd_Interview","Date_For_3rd_Interview","Date_of_Assessment",'"Assessment_Type"','"Inhouse_or_Outsourced"',"Assessment_Score ","Date_Offer_Sent","Date_Offer_Accepted",'"Candidate_Selected", "&_
"Candidate_Qualification"," StartDate",'"EE_Status"','"EE_Compliant"','"Reasons_for_Deviation"','"Promotion_or_Lateral_Movement"', '"Nationality"','"Comments"')"

enter image description here

I tried to add the "&_" but I'm still getting the same error

James Z
  • 12,209
  • 10
  • 24
  • 44
  • You have one string here: `"Insert into RECRUITMENT values (" JobID` which ends at `"`, and then you just have JobID without concatenation. And same thing continues all over – James Z Nov 28 '22 at 16:07

1 Answers1

1

The line continuation token is defined by a SPACE followed by an UNDERSCORE, followed by a NEWLINE.

Moreover, when immediately following a literal expression, the & character is a type hint for a Long, and the string literal won't convert into that data type: make sure there's always a space before and after the concatenation operators.

Replace "&_ with " & _ and the line continuations will work... But the inner concatenations are missing, "some string"someField"," is not legal syntax, needs to become "some string" & someField & "," to be valid.

Side note, with Rubberduck (free, open-source VBE add-in) autocompletion you would only need to hit ENTER in the middle of a long string literal to automatically have it correctly split-up and line-continuated.

Mathieu Guindon
  • 69,817
  • 8
  • 107
  • 235