greater than and less than in If statement

  • Thread starter klp via AccessMonster.com
  • Start date
K

klp via AccessMonster.com

I am using an If..then...elseif statement in the VB editor to determine what
report to print. I am having a problem with the >= And <= part of my
statement. Here is my statement: When I run this statement it will highlight
the <= part of my statement giving me a complie error of Expected:
expression. I have used this before, so I thought and never had any problems.
Not sure what's going on here. Any help appreciated.

If Me.lstTestLabel.Column(0) <= 2002.11 Then
DoCmd.OpenReport "2002 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
ElseIf Me.lstTestLabel.Column(0) >= 2003.01 AND <= 2003.25 Then
DoCmd.OpenReport "2003 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
ElseIf Me.lstTestLabel.Column(0) >= 2004.01 And <= 2004.20 Then
DoCmd.OpenReport "2004 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
ElseIf Me.lstTestLabel.Column(0) >= 2005.01 And <= 2005.29 Then
DoCmd.OpenReport "2005 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
ElseIf Me.lstTestLabel.Column(0) > 2006.01 Then
DoCmd.OpenReport "Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
End If
 
D

Dennis

klp via AccessMonster.com said:
I am using an If..then...elseif statement in the VB editor to determine what
report to print. I am having a problem with the >= And <= part of my
statement. Here is my statement: When I run this statement it will highlight
the <= part of my statement giving me a complie error of Expected:
expression. I have used this before, so I thought and never had any problems.
Not sure what's going on here. Any help appreciated.

If Me.lstTestLabel.Column(0) <= 2002.11 Then
DoCmd.OpenReport "2002 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
ElseIf Me.lstTestLabel.Column(0) >= 2003.01 AND <= 2003.25 Then
DoCmd.OpenReport "2003 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
ElseIf Me.lstTestLabel.Column(0) >= 2004.01 And <= 2004.20 Then
DoCmd.OpenReport "2004 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
ElseIf Me.lstTestLabel.Column(0) >= 2005.01 And <= 2005.29 Then
DoCmd.OpenReport "2005 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
ElseIf Me.lstTestLabel.Column(0) > 2006.01 Then
DoCmd.OpenReport "Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
End If
 
D

Dennis

You need to include the variable twice when using the AND statement

e.g.

ElseIf Me.lstTestLabel.Column(0) >= 2003.01 AND Me.lstTestLabel.Column(0) <=
2003.25 Then

etc...
 
K

klp via AccessMonster.com

DISREGARD. I totally had prego brain and didn't even think about adding the
main part of my statement after the AND part of the statement.
 
J

John Smith

Just a thought but you might find a case statement would make it clearer:

Select Case Left$(Me.lstTestLabel.Column(0),4)
Case 2002
DoCmd.OpenReport "2002 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
Case 2003
DoCmd.OpenReport "2003 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
Case 2004
DoCmd.OpenReport "2004 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
Case 2005
DoCmd.OpenReport "2005 Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
Case 2006
DoCmd.OpenReport "Testing Results by Test", acViewPreview,
WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"
End Select

Or you could go really minimalist:

DoCmd.OpenReport Left$(lstTestLabel,4) & " Testing Results by Test", _
acViewPreview, WhereCondition:=strWhere
DoCmd.close acForm, "Report Dialog by Test"

HTH
John
##################################
Don't Print - Save trees
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top