You could use this code:
Sub Macro2()
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
rs.Open "select t1.[Incident number], t1.[VICTIM_NO], t1.[NIB_CODE], t1.[NIB_CODE_DESC], null, " _
& " t2.[Incident number], t2.[Report Type], t2.[Report Type Description], " _
& " t2.[Incident Status], t2.[Incident Status Description], t2.[Open Investigation], " _
& " t2.[Incident Occurred], t2.[Incident Reported], t2.[Location of incident], " _
& " t2.[Zip], t2.[ZONE], t2.[RPA], t2.[Mapping X co-ordinate], t2.[Mapping Y co-ordinate] " _
& "from [Data Needing to Be Combined$A:D] t1 LEFT JOIN [Data Needing to Be Combined$F:S] t2 " _
& " on t1.[Incident number] = t2.[Incident number]", cn, adOpenStatic, adLockOptimistic, adCmdText
ThisWorkbook.Sheets(2).Range("2:" & Rows.Count).ClearContents
ThisWorkbook.Sheets(2).Range("A2").CopyFromRecordset rs
End Sub
Regards,
Antonio
Bookmarks