If..then else statements help

G

Guest

Good morning,

I use command button to preview a report of currently displaced name event
procedure for that command button is

stDocName = "Students Report"
If ("name")= "me!" Then
DoCmd.OpenReport stDocName, acPreview, , "[Name]= '" & Me![Name] & " '"
Else
Msgbox "There is no activity related to this student"
end If
In this name is a text field

what happens is even if there is a record for particular student insted of
opening he report, always else command is executed. The code worked perfectly
for first day ( I believe i had the same code first day) the problem started
from second day. Did I messed up while saving the document?? or there is
something wrong in the statement. Can this type of situation arise from some
change in report format??

Please help
 
M

Marshall Barton

senkurion said:
I use command button to preview a report of currently displaced name event
procedure for that command button is

If ("name")= "me!" Then
[snip]

That If statement doesn't make sense. Could you explain
what it's supposed to do?
 
G

Guest

ok let me explain,

Name is one of the field in report. This report contains the names of all
the students in school who may or may not have participated in all
activities.Each activities has different report.

In my form I hve a combo box in which I can select the name of all students
enrolled.

In the same form I have a different command buttons for example Math,
science etch

when I click one of these command buttons it gives me the reports of the
student which I selectd in combo buttons.
but not all students are involved in every activities. some student have no
activity in science.At present if I select a name in combo box and press the
science command button it gives the record of all the activities for that
student in science. BUT if the student has no activity in science it gives me
a blank report.

when there is no activity I wanted to se somethin like "sorry we dont have
any activity fo this student in science subject"

SO ("Name")="Me!" checks the currently displayed name of the student in
combo box of the form and matches with that of the name in report.

when I click the command button If the name matches it gives you the report
if there is no match of the name in certain activity it says "sorry we dont
have any activity fo this student in science subject"

I hope it is clear this time

thank you



Marshall Barton said:
senkurion said:
I use command button to preview a report of currently displaced name event
procedure for that command button is

If ("name")= "me!" Then
[snip]

That If statement doesn't make sense. Could you explain
what it's supposed to do?
 
G

Guest

further to my previous reply

at present to get the report for a student i do following

1. select the name of the student in combo box of form
2. Then click the command buttun say "science" in the same form. This gives
me all activities that student has performed in science.

this command button has follwing code for onclick event

stDocName = "Activities in Science"

DoCmd.OpenReport stDocName, acPreview, , "[Name]= '" & Me![Name] & " '"


I just wanted to add if...then..else statement to this code so if a student
has performed no activities in the field it will say
"sorry this student has no activity recorded in science" or something like
that.



I am using follwing code to ge the report



Marshall Barton said:
senkurion said:
I use command button to preview a report of currently displaced name event
procedure for that command button is

If ("name")= "me!" Then
[snip]

That If statement doesn't make sense. Could you explain
what it's supposed to do?
 
M

Marshall Barton

senkurion said:
further to my previous reply

at present to get the report for a student i do following

1. select the name of the student in combo box of form
2. Then click the command buttun say "science" in the same form. This gives
me all activities that student has performed in science.

this command button has follwing code for onclick event

stDocName = "Activities in Science"

DoCmd.OpenReport stDocName, acPreview, , "[Name]= '" & Me![Name] & " '"


I just wanted to add if...then..else statement to this code so if a student
has performed no activities in the field it will say
"sorry this student has no activity recorded in science" or something like
that.


If you want the report to display "No activity . . ."
instead of being blank, then add a text box control to the
report. Set the text box's control source expression to:

=IIf(HasData, Null, "sorry this student has no activity...")

If you want to suppress the report and pop up a message box,
then add this to the report's NoData event procedure:

MsgBox "sorry this student has no activity...")
Cancel = True

And back in the command button's code, add error handling to
ignore error 2501.
 
G

Guest

thanks man, it was useful

senkurion said:
ok let me explain,

Name is one of the field in report. This report contains the names of all
the students in school who may or may not have participated in all
activities.Each activities has different report.

In my form I hve a combo box in which I can select the name of all students
enrolled.

In the same form I have a different command buttons for example Math,
science etch

when I click one of these command buttons it gives me the reports of the
student which I selectd in combo buttons.
but not all students are involved in every activities. some student have no
activity in science.At present if I select a name in combo box and press the
science command button it gives the record of all the activities for that
student in science. BUT if the student has no activity in science it gives me
a blank report.

when there is no activity I wanted to se somethin like "sorry we dont have
any activity fo this student in science subject"

SO ("Name")="Me!" checks the currently displayed name of the student in
combo box of the form and matches with that of the name in report.

when I click the command button If the name matches it gives you the report
if there is no match of the name in certain activity it says "sorry we dont
have any activity fo this student in science subject"

I hope it is clear this time

thank you



Marshall Barton said:
senkurion said:
I use command button to preview a report of currently displaced name event
procedure for that command button is

If ("name")= "me!" Then
[snip]

That If statement doesn't make sense. Could you explain
what it's supposed to do?
 

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