I have a form with a project selection button. A user selects a project then clicks a button. When this happens a pass through SQL query is produced.
The code is here:
When executed I get the following Error:
When I copy and paste the SQL produced by debug.print (shown below) it runs fine both in access as a query and also within SSMS, suggesting the syntax is fine. Furthermore despite generating the error the code actually produces the required query, which runs fine. So I don't understand why am I getting the error.
V_Employees is a view on the SQL server.
The code is here:
Code:
Private Sub cmdIssueList_Click()
On Error GoTo err_cmdIssueList_Click
Dim strSql As String
Dim strQdfName As String
If IsNull(Me!cboSelectProject) Then
MsgBox "Please select a primary project before proceeding"
Else
Gbl_Project = Me!cboSelectProject.Value
strQdfName = "qdfIssueListByProject"
strSql = "SELECT i.I_ID As [ID], "
strSql = strSql & "i.I_Title As [Title], "
strSql = strSql & "i.I_Severity As [Sev], "
strSql = strSql & "i.I_LastUpdated As [Last Update], "
strSql = strSql & "i.I_Status As [Status], "
strSql = strSql & "e.Employee As [Champion], "
strSql = strSql & "i.I_TargetDate As [Target], "
strSql = strSql & "i.I_System As [System], "
strSql = strSql & "i.I_Component As [Component] "
strSql = strSql & "FROM tblIssues AS i INNER JOIN tblProjectIssues AS pi ON i.[I_ID] = pi.[I_ID] LEFT JOIN V_Employees e ON i.[I_Champion] = e.[StaffNo] "
strSql = strSql & "WHERE pi.P_ID='" & Me!cboSelectProject.Value & "'; "
Debug.Print strSql
Call CreateNamedQDF(strQdfName, strSql)
DoCmd.OpenForm "frmIssuesList", acNormal, , , , acWindowNormal
End If
exit_cmdIssueList_Click:
Exit Sub
err_cmdIssueList_Click:
MsgBox "Error No: " & Err.Number & vbCrLf & "Description: " & Err.Description & vbCrLf & "Error Line: " & Erl
Call Logger("Error", "risks-" & cstLatestVersion & ".Form_frmSwitchboard.cmdIssueList_Click", Erl, Err.Number, Err.Description)
Resume exit_cmdIssueList_Click
End Sub
When executed I get the following Error:
When I copy and paste the SQL produced by debug.print (shown below) it runs fine both in access as a query and also within SSMS, suggesting the syntax is fine. Furthermore despite generating the error the code actually produces the required query, which runs fine. So I don't understand why am I getting the error.
Code:
SELECT i.I_ID As [ID], i.I_Title As [Title], i.I_Severity As [Sev], i.I_LastUpdated As [Last Update], i.I_Status As [Status], e.Employee As [Champion], i.I_TargetDate As [Target], i.I_System As [System], i.I_Component As [Component] FROM tblIssues AS i INNER JOIN tblProjectIssues AS pi ON i.[I_ID] = pi.[I_ID] LEFT JOIN V_Employees e ON i.[I_Champion] = e.[StaffNo] WHERE pi.P_ID='UsersProject';
V_Employees is a view on the SQL server.