Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating reports

Status
Not open for further replies.

megavolt121

Technical User
Aug 5, 2002
18
US
I'm trying to create a report in which a few of the fields are numerical values of 0 or -1.(They are set by radio buttons in the forms). I'd like these fields to print No and yes respectively instead of 0 and -1 when I have a report generated. How do i do this?
 
Set the control source of a text box on your report to be something like this, of course changing to your field name(s):
Code:
=IIf([rdoField1] = 0,"No","Yes")
 
Ok question about this:
=IIf([rdoField1] = 0,"No","Yes")
Please bear w/ me since Access is realy new to me.

IIf - does this part create an If-Then statment?(i'm trying to relate to C++/Java)

[rdoField1] - field where my data is.

=0 - the if part, at which point it'll print out the first statement of no.

"yes" - the "then" part which prints yes if rdofield!=0.

I tried this and it gives me a #error when i preview the report using my field name though.
 
Another alternative you can try is an if statement in the OnPrint event procedure of the detail section (click in the detail section and then click the properties button). Put an unbound field on the report where you want the Yes/No to appear. I'm going to call it txtField2 for this code.

On Error GoTo ErrorField2

' Use the name of your option group here
If optNameofOptionGroup.value=0 Then
me.txtfield2.value="No"

Else
me.txtField2.value="yes"

End If

ExitField2:
Exit Sub

ErrorField2:
MsgBox err.Description
Resume ExitField2

End Sub Linda Adams
Linda Adams/Emory Hackman Official Web site Official web site for actor David Hedison:
 
Megavolt:

Given a field in your query named FRED, that returns a -1 for YES and a 0 for NO, Cosmos example should work for you, given that you place the text box in the same band as the piece of data you're evaluating.

To answer your questions, IIF is the "Immediate IF" function, that's kind of a stripped down IF..Then..Else construct.

IIF( {evaluation}, {True-Action}, {False-Action} )

=IIF([YourField] = 0, "YES", "NO")

You also might investigate changing the format of this field in the actual table design to print a YES or a NO instead of a -1 and 0. I find that's often the easiest way to do this. Go to the table design, an in the LOOKUP tab for this field, change the DISPLAY CONTROL to a TEXT BOX.

Jim


How many of you believe in telekinesis? Raise my hand...
Another free Access forum:
More Access stuff at
 
Cosmo, Wildhare, all

I've tried the code that cosmo gave me up in the 2nd post. I have four different fields:
Stage
Stage(1)
Stage(2)
Stage(3)

Now this code gives me a #Error for stage, Stage(2) and Stage(3)... but for some reason Stage(1) works fine. I made sure the code was right and that the fields all eitehr have a -1 or 0 in there.. Any clues?!
 
From Access help:
Code:
#Error? or #Name? appears in a control.

#Error? or #Name? may appear in a control for a number of reasons. To correct the problem, do the following:

·	Make sure that the field specified in the control's ControlSource property hasn't been removed from the underlying table, query, or SQL statement.
·	Check the spelling of the field name in the control's ControlSource property.
·	If you specified an expression in the control's ControlSource property, make sure that there is an equal sign preceding the expression.
·	Make sure that there are brackets around references in expressions to control or field names that include spaces. For example, to subtract a Shipped Date field from a Required Data field, enter the following expression: =[Required Date]-[Shipped Date].
 
I'd get rid of the parentheticals in field names, for one thing. Although that doesn't seem to be the problem, as "stage(1)" works but the others don't, it can only lead to problems down the road. I make it a practice, and try to drum it in to my student's heads, that field names should contain ONLY Letters A through Z and the occastional NUMBER. If they have to hit the SHIFT key or anything east of P, L and M on the keyboard, they're gonna be in trouble sooner or later.. LOL

Jim Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
The message says #Error.

I've checked the Statements and I'm using:
=IIf([Stage]=0,"No","Yes")

The appropriate field for data is named Stage and still exists. when using the form and clicking on the radio buttons, I'll still get values of 0 or -1 in the Stage field.
 
I've now had another problem. In my first report, Parts, I put in: =IIf([Stage]=0,"No","Yes") and it would print out Yes and No for all four fields I wanted. Now when I create another report and use the same exact code using data from the same table(just a different query), it gives the #error message again. What should i do?
 
from the same table(just a different query), it gives the #error message again. What should i do?

Give up and go home? ... [smile]...

Somethings daffy here, and it ain't no duck.

Is this db small enough and non-so-personal enough to ZIP down to a manageable size and ship to me? It seems like you're doing everything correctly, and the bugger is just being recalcitrant.

I'm running out for KFC in a few, but I'll be back

6:25 PM EDT New Jersey Standard Daylight Savings and Investment Time

PS Email is on my site..

Jim Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
Sent to the mailto:webmaster@jmhare.com 558kb.
3:51 PM Pacific Time
 
Alan (MegaVolt121 to his friends..) asked me to explain.

He was altering the CONTROL SOURCE of the actual StageX field - changing it from StageX to "IIF(StageX...)" - that doesn't work, because since there's no object named "StageX" on the report anymore, Access is yelling down the alley.

In this situation, he needs to place an unbound TEXT BOX for each of the evaluations, and use the IIF... syntax there. Then he can make the four StageX objects invisible.

It could have been done in the query too, but I didn't have the heart to tell him...

Alan, your StageX fields in the PART table should be YES/NO fields, not NUMBER fields, too, so your Option buttons on the form work right.


Plus, are any of your PARTS used in more than one Stage? If not, why not just use one Field called STAGE, and stick a 1, 2, 3 or 4 in it?

I could do more to fix this up but I'd have to send MDD/Northrup an $invoice$... LOL

Jim
Me? Ambivalent? Well, yes and no....
Another free Access forum:
More Access stuff at
 
Jim thanks a lot that fixed those problems and I think i'm getting the idea now of how to do this better, but I just emailed u one more question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top