I have a SQL from a recordsource that I am trying to put to code behind a command button so that when the user clicks on the command button the recordsource changes. I have the string together but am having problems understanding when to use single and double quotes. I understand that I need to use single if the variable is a text string but I haven't done this with a trim before and am pulling out my hair. can someone please help me understand where and why to use single quotes in this string
Code:
Private Sub cmdcraft_Click()
Dim strnewrecord As String
strnewrecord = "SELECT CraftT.Craft, CraftT.Specialty, JobCraftT.Hours, " _
& "Trim([department] "& " , " & [system] & " , " & [asset] & " , " & [component]") AS Task, " _
& "WorkQueT.SchInd, JobT.JobID, WorkQueT.Summary, WorkT.WorkType, WorkQueT.WorkQueID, JobT.SafeWorkPermit, " _
& "JobT.HoursPlanned, JobT.ContractorsNeeded, JobT.PartsStatus, JobT.schedule, WorkQueT.ScheduledDate, " _
& "WorkQueT.ScheduleTime, [6AssetT].Asset" _
& "FROM (JobCraftT RIGHT JOIN ((((((WorkQueT INNER JOIN 4DepartmentT ON WorkQueT.DeptID = [4DepartmentT].DeptID) " _
& "INNER JOIN 5SystemT ON WorkQueT.SystemID = [5SystemT].SystemID) INNER JOIN 6AssetT ON WorkQueT.AssetID = [6AssetT].AssetID) " _
& "INNER JOIN 7ComponentT ON WorkQueT.ComponentID = [7ComponentT].ComponentID) INNER JOIN WorkT ON WorkQueT.WorkID = WorkT.WorkID) " _
& "INNER JOIN JobT ON WorkQueT.WorkQueID = JobT.WorkQueID) ON JobCraftT.JobID = JobT.JobID) " _
& "LEFT JOIN CraftT ON JobCraftT.CraftID = CraftT.CraftID " _
& "WHERE (((JobT.schedule)=True))ORDER BY WorkQueT.SchInd DESC; " _
Debug.Print (strnewrecord)
'Me.RecordSource = strnewrecord
End Sub