Ok, I’m lost. I have been working on this for over a week and can’t find the solution or figure it out. :banghead: I have three queries built from two unrelated tables (DataFile and tblBLS).
DataFile:
ContractorName
NAICS
Year1
Year2
Year3
tblBLS:
NAICS
BLSYear (this includes 4 years of data, separated by NAICS )
TCIR
The queries are used to pull information from both tables based on year (qryBLS1: DataFile.Year1=tblBLS.BLSYear, qryBLS2: DataFile.Year2=tblBLS.BLSYear, and qryBLS3: DataFile.Year3=tblBLS.BLSYear) and perform calculations (there are more fields in each table, but the primary data is pulled by year and matching NAICS; these variables are listed as numbers in the tables). I’m sure there are easier ways, but after struggling for a couple of weeks, I just decided to split out my one gargantuan (I love that word) query into three, pool them together into another query to use a report. Everything works great until Year1 does not match any BLSYear. This is fine for the individual queries, but when I try to pull the three together for the report, I get no data (since qryBLS1 is not working). Any thoughts on how I can still get the other two queries to pull information, even if the one is not producing results? I can put “Data not available” on the report, but I can’t get anything to load (sometimes the DataFile information is more up to date than the BLS data – It could lag one year behind). Here is the SQL for the query not working:
SELECT DISTINCT DataFile.ContractorName, DataFile.Year1, DataFile.Year2, DataFile.Year3,
IIf([NC]=[NC2] And [DataFile]![Year1]=[tblBLS]![BLSYear],[tblBLS]![TCIR],"") AS BTCIR1,
IIf([NC]=[NC2] And [DataFile]![Year2]=[tblBLS]![BLSYear],[tblBLS]![TCIR],"") AS BTCIR2,
IIf([NC]=[NC2] And [DataFile]![Year3]=[tblBLS]![BLSYear],[tblBLS]![TCIR],"") AS BTCIR3,
Left([DataFile]![NAICS],3) AS nc,
Left([tblBLS]![NAICS],3) AS nc2, *
FROM DataFile, tblBLS
WHERE (((DataFile.ContractorName)=[Forms]![frmReports]![cboContractorName]) AND ((DataFile.Year1)=[tblBLS]![BLSYear]) AND ((Left([DataFile]![NAICS],3))=Left([tblBLS]![NAICS],3) And (Left([DataFile]![NAICS],3))=Left([tblBLS]![NAICS],3) And (Left([DataFile]![NAICS],3))=Left([tblBLS]![NAICS],3)));
I tried changing the AND statements to OR and got more records than I bargained for! I also tried to remove the DataFile.Year requirments all together and again, ended up with beaucoup records. Any help would be appreciated. Thank you.
DataFile:
ContractorName
NAICS
Year1
Year2
Year3
tblBLS:
NAICS
BLSYear (this includes 4 years of data, separated by NAICS )
TCIR
The queries are used to pull information from both tables based on year (qryBLS1: DataFile.Year1=tblBLS.BLSYear, qryBLS2: DataFile.Year2=tblBLS.BLSYear, and qryBLS3: DataFile.Year3=tblBLS.BLSYear) and perform calculations (there are more fields in each table, but the primary data is pulled by year and matching NAICS; these variables are listed as numbers in the tables). I’m sure there are easier ways, but after struggling for a couple of weeks, I just decided to split out my one gargantuan (I love that word) query into three, pool them together into another query to use a report. Everything works great until Year1 does not match any BLSYear. This is fine for the individual queries, but when I try to pull the three together for the report, I get no data (since qryBLS1 is not working). Any thoughts on how I can still get the other two queries to pull information, even if the one is not producing results? I can put “Data not available” on the report, but I can’t get anything to load (sometimes the DataFile information is more up to date than the BLS data – It could lag one year behind). Here is the SQL for the query not working:
SELECT DISTINCT DataFile.ContractorName, DataFile.Year1, DataFile.Year2, DataFile.Year3,
IIf([NC]=[NC2] And [DataFile]![Year1]=[tblBLS]![BLSYear],[tblBLS]![TCIR],"") AS BTCIR1,
IIf([NC]=[NC2] And [DataFile]![Year2]=[tblBLS]![BLSYear],[tblBLS]![TCIR],"") AS BTCIR2,
IIf([NC]=[NC2] And [DataFile]![Year3]=[tblBLS]![BLSYear],[tblBLS]![TCIR],"") AS BTCIR3,
Left([DataFile]![NAICS],3) AS nc,
Left([tblBLS]![NAICS],3) AS nc2, *
FROM DataFile, tblBLS
WHERE (((DataFile.ContractorName)=[Forms]![frmReports]![cboContractorName]) AND ((DataFile.Year1)=[tblBLS]![BLSYear]) AND ((Left([DataFile]![NAICS],3))=Left([tblBLS]![NAICS],3) And (Left([DataFile]![NAICS],3))=Left([tblBLS]![NAICS],3) And (Left([DataFile]![NAICS],3))=Left([tblBLS]![NAICS],3)));
I tried changing the AND statements to OR and got more records than I bargained for! I also tried to remove the DataFile.Year requirments all together and again, ended up with beaucoup records. Any help would be appreciated. Thank you.