Hi,
Haven't used Excel in a while to do this, but am fixing/adding to some older code.
I have a query that joins to two tables. When run in Access (and the % changed to *) it runs. In the VBA coding, it runs (no error) but doesn't return the matching fields in the linked table.
Any ideas what I'm doing wrong?
To me it looks fine and it isn't erroring, which is weird. Its just not working.Code:strSql = "SELECT" & vbCrLf strSql = strSql & " 'Jag' as Brand, AL.Mondial_Ref, AL.Registration_Number" & vbCrLf strSql = strSql & " , AL.Customer_Name, AL.Dealer_Code" & vbCrLf strSql = strSql & " , AL.Chassis_Number, AL.ReasonCode" & vbCrLf strSql = strSql & " , tblDFredRefs.FREDRef, TB_CDSI.Full_Name, tblDFredRefs.ConfirmedValidOn" & vbCrLf strSql = strSql & " FROM (TBL_Mondial_ActiveList as AL" & vbCrLf strSql = strSql & " LEFT JOIN tblDFredRefs ON AL.Mondial_Ref = tblDFredRefs.CHRef" & vbCrLf strSql = strSql & " ) LEFT JOIN TB_CDSI ON tblDFredRefs.ConfirmedValidBy = TB_CDSI.UserID" & vbCrLf strSql = strSql & " WHERE AL.ReasonCode Like 'FRED%'" & vbCrLf strSql = strSql & " UNION ALL" & vbCrLf strSql = strSql & " SELECT " & vbCrLf strSql = strSql & " 'LR' as Brand, AL.Mondial_Ref, AL.Registration_Number" & vbCrLf strSql = strSql & " , AL.Customer_Name, AL.Dealer_Code" & vbCrLf strSql = strSql & " , AL.Chassis_Number, AL.ReasonCode" & vbCrLf strSql = strSql & " , tblDFredRefs.FREDRef, TB_CDSI.Full_Name, tblDFredRefs.ConfirmedValidOn" & vbCrLf strSql = strSql & " FROM (TBL_Mondial_ActiveList1 as AL" & vbCrLf strSql = strSql & " LEFT JOIN tblDFredRefs ON AL.Mondial_Ref = tblDFredRefs.CHRef" & vbCrLf strSql = strSql & " ) LEFT JOIN TB_CDSI ON tblDFredRefs.ConfirmedValidBy = TB_CDSI.UserID" & vbCrLf strSql = strSql & " WHERE AL.ReasonCode Like 'FRED%'" & vbCrLf




Reply With Quote