Syntax Error

PC User

Registered User.
Local time
Today, 05:54
Joined
Jul 28, 2002
Messages
193
I have a function that builds a filter and it get a syntex error. It has three components and I must be missing something in combining them into the filter. SpecID and ReviewID are numbers. Selected is a checkbox and 'Yes' is a string. Can anyone see the source of the Syntax Error?

Code:
Private Function PlanFilter()
    Dim strFilter1 As String, strFilter2 As String, strFilter3 As String
        strFilter1 = "[SpecID] =  " & [Forms]![frmMainEntry]![SpecID]
        strFilter2 = "[ReviewID] =  " & [Forms]![frmMainEntry].Form!fctlReviewRequests!ReviewID
        strFilter3 = "[Selected] =  'Yes'"
        gstrFilter = strFilter1 & " And " & strFilter2 & " And " & strFilter3 & ";"
        Debug.Print gstrFilter
End Function

Thanks,
PC
 
I obviously can't check your form values, but think the syntax looks ok.

Code:
Private Function PlanFilter()
    Dim strFilter1 As String, strFilter2 As String, strFilter3 As String, 
    Dim gstrfilter As String
    Dim Temp1 As Integer, Temp2 As Integer
    
    Temp1 = 20
    Temp2 = 30
    
    strFilter1 = "[SpecID] =  " & Temp1
    strFilter2 = "[ReviewID] =  " & Temp2
    strFilter3 = "[Selected] =  'Yes'"
    gstrfilter = strFilter1 & " And " & strFilter2 & " And " & strFilter3 & ";"
    MsgBox gstrfilter
End Function

Are they supposed to be different brackets in your filter? Round instead of square?

i.e. "(SpecID) = "
 
If the query syntax is correct, then it might be the subform reference. I'm trying to reference a control ReviewID on a subform fsubReviewRequests through the subform control fctlReviewRequests that resides on the form frmMainEntry.

Code:
strFilter2 = "[ReviewID] =  " & [Forms]![frmMainEntry].Form!fctlReviewRequests!ReviewID

I've gone through this a number of times, but do you see an error in this code?

Thanks,
PC
 
Check it on its own.

dim test as string
test = [Forms]![frmMainEntry].Form!fctlReviewRequests!ReviewID
msgbox test

If it comes up with a numeric value, then the reference is ok.
 

Users who are viewing this thread

Back
Top Bottom