I have a form set up with various options to select records. I'm trying to write a dynamic sql query which I can use as the record source. I've set it up as a function which I then set as the form's recordsource on load.
Everytime I open the form though, I get a Runtime error 3135. Syntax error in JOIN operation. This is the first time I've used the join in SQL and I really can't figure out what is wrong. Can anyone spot anything?
Everytime I open the form though, I get a Runtime error 3135. Syntax error in JOIN operation. This is the first time I've used the join in SQL and I really can't figure out what is wrong. Can anyone spot anything?
Code:
Public Function Gen_Filter(ByVal modnum As String, ByVal officer As Variant, ByVal tf As Variant, tt As Variant, cf As Variant, ct As Variant, ic As Variant) As String
On Error GoTo Err_Gen_Filter
Dim strsql As String
Dim strsql1 As String
strsql = "SELECT DISTINCT Standards.Standard_ID" & Chr(13) & Chr(10) & _
"FROM Standards LEFT JOIN Standard_Responsible_Officers" & Chr(13) & Chr(10) & _
"ON Standards.Standard_ID = Standard_Reponsible_Officers.Standard_ID " & Chr(13) & Chr(10) & _
"WHERE Standards.Standard_ID <> 0 "
MsgBox strsql
If (Len(Nz(modnum, "")) <> 0) Then
strsql = strsql & "AND ((Standards.Module_Number) = " & modnum & ") " & Chr(13) & Chr(10)
End If
MsgBox strsql
If (Len(Nz(officer, "")) <> 0) Then
strsql = strsql & "AND ((Standard_Responsible_Officers.Responsible_Officer) = " & officer & ") " & Chr(13) & Chr(10)
End If
MsgBox strsql
If (Len(Nz(tf, "")) <> 0) Then
strsql = strsql & "AND ((Standards.Target_Date) >= " & tf & ") " & Chr(13) & Chr(10)
End If
MsgBox strsql
If (Len(Nz(tt, "")) <> 0) Then
strsql = strsql & "AND ((Standards.Target_Date) <= " & tt & ") " & Chr(13) & Chr(10)
End If
MsgBox strsql
If (ic = "-1") Then
If (Len(Nz(cf, "")) <> 0) Then
strsql = strsql & "AND ((Standards.Completed_Date) >= " & cf & ") " & Chr(13) & Chr(10)
End If
If (Len(Nz(ct, "")) <> 0) Then
strsql = strsql & "AND ((Standards.Completed_Date) <= " & ct & ") " & Chr(13) & Chr(10)
End If
Else
strsql = strsql & "AND (len(Nz(Standards.Completed_Date,""""))= 0)"
End If
MsgBox strsql
strsql = strsql & ";"
Gen_Filter = strsql
Exit_Gen_Filter:
Exit Function
Err_Gen_Filter:
MsgBox Err.Description
Resume Exit_Gen_Filter
End Function