Numeric If...Then...Elseif:...Else...End If statement problem

G

Guest

Good morning,

Using WinXP and Access2002.

I should be able to do this; perhaps my brain is on vacation.

On a form, bound control [intFreq], I enter a number, i.e. 14.070
Same form, in another bound control [intBand], I need to calculate/determine
what was in the first control and programmatically enter a value in the
second control. Both controls are 'number fields', general number format.

In the Afterupdate event of the first control, I have this:

If me.intFreq <= 1.8 and >= 2 Then
me.intBand = 160
Elseif: me.intFreq <= 3.500 and >= 4 Then
me.intBand = 80
Elseif: me.intFreq <=7 and >= 7.3 Then
me.intBand = 40
Else:
End If


The compile error I get is "Syntax error". I checked the Help in Access and
did a search on If…Then…Else statements in the discussion group and did not
find a related topic. I also checked VBA Help, but I was unable to determine
the meaning of "Block If" well enough to help me.
 
M

Matthias Klaey

Jim Ory said:
Good morning,

Using WinXP and Access2002.

I should be able to do this; perhaps my brain is on vacation.

On a form, bound control [intFreq], I enter a number, i.e. 14.070
Same form, in another bound control [intBand], I need to calculate/determine
what was in the first control and programmatically enter a value in the
second control. Both controls are 'number fields', general number format.

In the Afterupdate event of the first control, I have this:

If me.intFreq <= 1.8 and >= 2 Then
me.intBand = 160
Elseif: me.intFreq <= 3.500 and >= 4 Then
me.intBand = 80
Elseif: me.intFreq <=7 and >= 7.3 Then
me.intBand = 40
Else:
End If


The compile error I get is "Syntax error". I checked the Help in Access and
did a search on If…Then…Else statements in the discussion group and did not
find a related topic. I also checked VBA Help, but I was unable to determine
the meaning of "Block If" well enough to help me.

The syntax error is in the condition: Instead of
If me.intFreq <= 1.8 and >= 2 Then

you need to write

If me.intFreq <= 1.8 and me.intFreq >= 2 Then

BTW this will never be true. Dit you mean

If me.intFreq >= 1.8 and me.intFreq <= 2 Then

(both commens apply to the ElseIf conditions too).

HTH
Matthias Kläy
 
G

Guest

Matthias Kläy wrote:

you need to write

If me.intFreq <= 1.8 and me.intFreq >= 2 Then

BTW this will never be true. Dit you mean

If me.intFreq >= 1.8 and me.intFreq <= 2 Then

(both commens apply to the ElseIf conditions too).

Thanks Matthias,

For the syntax correction and my improper use of 'greater than' and 'less
than' symbols. I would still be trying to figure that one out.
 

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

Similar Threads

Help With If and Else If Statement 5
If...ElseIf...Then Statement 3
If Then Else statment Help 5
If..else..then statement 5
If...Elseif...Else 2
shorter method than elseif 1
if elseif help 16
ElseIf question 2

Top