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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing an IF THEN ELSE statement in a report

Status
Not open for further replies.
May 30, 2002
78
0
0
US
Hi,

I'm generating a report based on a query. The query produces an attribute that has either a value either 0 or 1. I need the report to basically run the following logic:

If <value> = 0 Then
Textbox.Control Source = &quot;Bears&quot;
Else
Textbox.Control Source = &quot;Packers&quot;


I'm assuming &quot;Control Source&quot; is simply the property containing the text to be displayed. How can I accomplish this task?

Thanks,

MG
 
Like this:
If [FieldInReport] = 0 Then
Textbox = &quot;Bears&quot;
Else
Textbox = &quot;Packers&quot;
end if

Put this in the Open event of the form.

On the other hand, it might be better to make your field evaluate to one of the two values, instead of 1 or 0. It's clear you've done some simplicfication, and I can't be sure what's been simplified and what hasn't, or how your field gets its value, but it might just be simpler to build the query in such a way that it generates the data you want to display.

If you want, post your sql and we can see how to do that.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
SELECT Household.Contact, Household.[HH Family Name], [Capital Campaign Contributions].[HH Campaign Contribution Date], [Capital Campaign Contributions].[HH Campaign Amount], [Capital Campaign Contributions].[HH Campaign Amount]*0 as Type

FROM Household INNER JOIN [Capital Campaign Contributions] ON Household.[Household ID] = [Capital Campaign Contributions].[Householdr ID]

UNION ALL
SELECT Member.[Mem First Name], Member.[Mem Last Name], [Weekly Contirubution].[Mem Weekly Contribution Date], [Weekly Contirubution].[Mem Weekly Contribution Amount], [Weekly Contirubution].[Mem Weekly Contribution Amount]^0 as Type

FROM Member INNER JOIN [Weekly Contirubution] ON Member.[Member ID] = [Weekly Contirubution].[Member ID]

ORDER BY Household.Contact;


Here's the SQL (unchanged). Basically, I needed to distinquish which SELECT statement produced the record. Ideally, Type would equal &quot;Campaign Contribution&quot; if produced in the first statement and &quot;Weekly Contribution&quot; if produced in the second statement.

Thanks,

MG
 
you could yous an iif statment in another query that wraps that one
 
Heh. It's gonna hurt how simple this is, but that's how we have fun with SQL, right??

Jeremy

SELECT Household.Contact, Household.[HH Family Name], [Capital Campaign Contributions].[HH Campaign Contribution Date], [Capital Campaign Contributions].[HH Campaign Amount], &quot;Campaign Contribution&quot; as Type

FROM Household INNER JOIN [Capital Campaign Contributions] ON Household.[Household ID] = [Capital Campaign Contributions].[Householdr ID]

UNION ALL
SELECT Member.[Mem First Name], Member.[Mem Last Name], [Weekly Contirubution].[Mem Weekly Contribution Date], [Weekly Contirubution].[Mem Weekly Contribution Amount], &quot;Weekly Contirubution&quot; as Type

FROM Member INNER JOIN [Weekly Contirubution] ON Member.[Member ID] = [Weekly Contirubution].[Member ID]

ORDER BY Household.Contact;
=============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
No worries. Glad to help.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top