Syntax Error In Code . .

Evagrius

Registered User.
Local time
Today, 02:50
Joined
Jul 10, 2010
Messages
170
Hi, this code is in a combobox. I can't seem to get it to function. I am siply trying to filter the form by the Field [YEAR] for only 2008 and 2009. The field type is TEXT and not date.

Code:
Private Sub cboFields_BeforeUpdate(Cancel As Integer)
    Me.FilterOn = False
    If IsNull(Me.cboFields) Then
        Me.FilterOn = False
    Else
        Me.Filter = "[Year] = IN('2009','2010')"
        Me.FilterOn = True
    End If
End Sub
 
That looks okay offhand. Try it in the after update event instead of the before. I would only use the before update event for validation.

Though it wouldn't cause an error, the first portion of the code is not necessary. You've already set the property to False.
 
Hi, this code is in a combobox. I can't seem to get it to function. I am siply trying to filter the form by the Field [YEAR] for only 2008 and 2009. The field type is TEXT and not date.

Code:
Private Sub cboFields_BeforeUpdate(Cancel As Integer)
    Me.FilterOn = False
    If IsNull(Me.cboFields) Then
        Me.FilterOn = False
    Else
[COLOR=#ff0000][B]      Me.Filter = "[Year] = IN('2009','2010')"[/B][/COLOR]
        Me.FilterOn = True
    End If
End Sub

I believe that your SQL Syntax for Me.Filter is incorrect, and that the proper Syntax should be something like the following:

Me.Filter = "[Year] IN ('2009','2010')"
 
Oops; missed the "=" in there. That will certainly cause a problem. :o
 
Thanks you both very much!! If it would not be asking too much, since I am filtering for 2009 and 2010, how can I adjust the code so that the records show the 2009s and then the 2010s. Thank you again!
 
Thanks you both very much!! If it would not be asking too much, since I am filtering for 2009 and 2010, how can I adjust the code so that the records show the 2009s and then the 2010s. Thank you again!

Looking up the SQL Syntax for the "ORDER BY" statement should point you in the right direction. post back with any questions.
 
What you encountered was the sadly-not-uncommon Paul brain cramp. :p

All is forgiven, I am sure. Heaven knows I am not perfect either. In fact if we were all perfect, this forum would not be half as much fun as it is.
 
Well, I've tried several option in my effort to learn, but I am just not getting it. The order by is causing my error. . .


Code:
Private Sub cboFields_AfterUpdate()
    If IsNull(Me.cboFields) Then
        Me.FilterOn = False
    Else
        Me.Filter = "[Year] IN ('2008','2009') order by [Year]"
        Me.FilterOn = True
    End If
End Sub
 
An order by does NOT go in the filter. It goes in the Order by property:

Me.OrderBy = "[Year]"
Me.OrderByOn = True

they are SEPARATE items.
 
SOS - Thank You for that lesson and solving the issue. Thanks . .
 

Users who are viewing this thread

Back
Top Bottom