IF ElseIf and Else

A

ANDRLIMO

I am having a problem with the code that i have written. I can get the last
elseif statement to work but the if and first elseif doesnt want to work
correctly. Below is the code that i used, and any help with this would be
greatly appreciated.

Private Sub Command41_Click()
If Me.APPROVED = "yes" And Me.DISAPPROVED = "0" Then
DoCmd.OpenReport "rptdd1970", acViewPreview
ElseIf Me.APPROVED = "0" And Me.DISAPPROVED = "yes" Then
intanswer = MsgBox("Your request was disapproved.", vbOKOnly)
ElseIf Me.APPROVED = "0" And Me.DISAPPROVED = "0" Then
intanswer = MsgBox("Your request hasn't been reviewed yet.",
vbokayonly)
End If
End Sub

Thanks,

Andrew
 
D

Douglas J. Steele

What are APPROVED and DISAPPROVED? If they're check boxes, using quotes is
wrong:

Private Sub Command41_Click()
If Me.APPROVED = True And Me.DISAPPROVED = False Then
DoCmd.OpenReport "rptdd1970", acViewPreview
ElseIf Me.APPROVED = False And Me.DISAPPROVED = True Then
intanswer = MsgBox("Your request was disapproved.", vbOKOnly)
ElseIf Me.APPROVED = False And Me.DISAPPROVED = False Then
intanswer = MsgBox("Your request hasn't been reviewed yet.",vbokayonly)
End If
End Sub
 
M

Marshall Barton

ANDRLIMO said:
I am having a problem with the code that i have written. I can get the last
elseif statement to work but the if and first elseif doesnt want to work
correctly. Below is the code that i used, and any help with this would be
greatly appreciated.

Private Sub Command41_Click()
If Me.APPROVED = "yes" And Me.DISAPPROVED = "0" Then
DoCmd.OpenReport "rptdd1970", acViewPreview
ElseIf Me.APPROVED = "0" And Me.DISAPPROVED = "yes" Then
intanswer = MsgBox("Your request was disapproved.", vbOKOnly)
ElseIf Me.APPROVED = "0" And Me.DISAPPROVED = "0" Then
intanswer = MsgBox("Your request hasn't been reviewed yet.",
vbokayonly)
End If
End Sub


What is the field type (in the table) for APPROVED and
DISAPPROVED? It sure looks strange for them to be Text
fields with either "Yes" or "0". More likely they are
Yes/No fields that contain either True or False. If that's
really what you have, then it could be:

Private Sub Command41_Click()
If Me.APPROVED And Not Me.DISAPPROVED Then
DoCmd.OpenReport "rptdd1970", acViewPreview
ElseIf Not Me.APPROVED And Me.DISAPPROVED Then
intanswer = MsgBox("Your request was disapproved.",
vbOKOnly)
ElseIf Not Me.APPROVED And Not Me.DISAPPROVED Then
intanswer = MsgBox("Your request hasn't been
reviewed yet.", vbOKOnly)
End If
End Sub

Note the corrected spelling of vbOKOnly
 
A

ANDRLIMO

Doug,

Thank you very much that was the problem this is the first time i have ever
done an If statement and i am still in my infancy writing code this was very
helpful and helped correct the problem. Again thanks for the help.

Andrew
What are APPROVED and DISAPPROVED? If they're check boxes, using quotes is
wrong:

Private Sub Command41_Click()
If Me.APPROVED = True And Me.DISAPPROVED = False Then
DoCmd.OpenReport "rptdd1970", acViewPreview
ElseIf Me.APPROVED = False And Me.DISAPPROVED = True Then
intanswer = MsgBox("Your request was disapproved.", vbOKOnly)
ElseIf Me.APPROVED = False And Me.DISAPPROVED = False Then
intanswer = MsgBox("Your request hasn't been reviewed yet.",vbokayonly)
End If
End Sub
I am having a problem with the code that i have written. I can get the last
elseif statement to work but the if and first elseif doesnt want to work
[quoted text clipped - 15 lines]
 
M

Mike Painter

ANDRLIMO said:
Doug,

Thank you very much that was the problem this is the first time i
have ever done an If statement and i am still in my infancy writing
code this was very helpful and helped correct the problem. Again
thanks for the help.

Andrew
I've never liked ELSE IF AND find CASE a much clearer method.
 
V

Vincent Sichilaba

TABLE

Student number

Name

Mark

Result





I would like to set the if..then..else statement in Microsoft access using
the properties on a bound form having already created the table.



If the mark is less than 50 then the result should display fail

If the mark is between 50 and 60 then the result should display pass

If the mark is between 61 and 70 then the result should display credit

If the mark is between 71 and 80 then the result should display merit

If the mark is between 80 and 100 then the result should display distinction



l Please help me and show me how this can be achieved

l A step by step explanation will be high appreciated with base on
the field used in the table above

l How do you incorporate the lostfocus and gotfocus in this



Iam using office 2003 suite.
 
J

John W. Vinson

On Tue, 13 Apr 2010 08:27:01 -0700, Vincent Sichilaba <Vincent
TABLE
Student number
Name
Mark
Result

I would like to set the if..then..else statement in Microsoft access using
the properties on a bound form having already created the table.

Well, you could do it with code using a SELECT CASE statement, but that's far
from the best solution.
If the mark is less than 50 then the result should display fail
If the mark is between 50 and 60 then the result should display pass
If the mark is between 61 and 70 then the result should display credit
If the mark is between 71 and 80 then the result should display merit
If the mark is between 80 and 100 then the result should display distinction

Create a table named Grades with fields LOW, HIGH, and GRADE. Fill it with the
above values, e.g. Low=0, High=50, Grade = "Fail"; Low=51, High = 60, Grade =
"Pass", and so on.

Create a Query including your table and the Grades table. Initially join the
two tables by joining Mark to Low. Then select View... SQL and edit the SQL
view of the query to change

ON Table.Mark = Grades.Low

to

ON Table.Mark >= Grades.Low AND Table.Mark <= Grades.High

If you open this query, or base a form or report on it and open *that*, you'll
see the appopriate grade for each student.
l Please help me and show me how this can be achieved

l A step by step explanation will be high appreciated with base on
the field used in the table above

l How do you incorporate the lostfocus and gotfocus in this

You wouldn't. Wrong tool for the job.
 

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