I've been stuck on this same sql statement for way too long and I'm about to throw my hands in the air and walk away. I'm just learning this database stuff. This original database was 2003 and I converted it to 2010. Nothing is working for me. For example, I'm trying to view a report and I keep receiving an error message: The SELECT statement includes a reserved word or an argument that is misspelled or missing, or the punctuation is incorrect. I got to the module and debug and I've been stuck here for weeks.
Code:
"Option Compare Database Const folder_Name = "\\waufs1-cluster\shared\Claims Res. Wausau\Access Files\" Function Age_Status() Dim sql_criteria As String Dim rst_report Dim sql_LessAge, sql_GreaterAge As String Dim sql_LessLAge, sql_GreaterLAge As String Dim sql_Location As String Dim contract, contract_name, contract_file As String Dim tmp_report As String Dim strcount As Long contract = call_Contract If (contract = "allexcel") Then contract_name = "Tdefic" Else contract_name = UCase(Left(contract, 1)) & Right(contract, Len(contract) - 1) End If contract_file = Check_Files(contract) If (contract_file = "") Then Exit Function End If File_Time = FileDateTime(folder_Name & contract_file & ".txt") tmp_report = fosusername If (Nz(Forms![frm_Main]![LESSTHANAGE], "") <> "") Then sql_LessAge = "(([AGE])<[Forms]![frm_Main]![LESSTHANAGE]) AND " End If If (Nz(Forms![frm_Main]![greaterthanage], "") <> "") Then sql_GreaterAge = "(([AGE])>[Forms]![frm_Main]![greaterthanage]) AND " End If If Nz(Forms![frm_Main]![combolocation], "") <> "" Then sql_loc = "((tbl_" & contract_file & ".[LOC]) = [Forms]![frm_Main]![combolocation]) AND " End If sql_criteria = "SELECT AGE, Count(IIf([N/I]='N','YES')) AS Non, Count(IIf([N/I]='I','YES')) AS Inst, Count(IIf([N/I]='O','YES')) AS Outpt, Count(ICN) AS Total, '" & contract_name & "' AS CONTRACT, '" & File_Time & "' AS [TIME] into " & tmp_report & _ "FROM tbl_" & contract_file & " INNER JOIN " & contract_name & "_LOCS ON tbl_" & contract_file & ".LOC = " & contract_name & "_LOCS.LOC" & _ "WHERE ((" & sql_loc & sql_LessAge & sql_GreaterAge & "(" & contract_name & "_LOCS.DEPT) = [Forms]![frm_Main]![combodepartment]))" & _ "GROUP BY AGE" & _ "ORDER BY AGE DESC;" DoCmd.SetWarnings False DoCmd.RunSQL (sql_criteria)<----(this is highlighed yellow after debugging) DoCmd.OpenReport "rpt_AgeStatus", acViewPreview DoCmd.SetWarnings True End Function"
Comment