If then Else

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created a report to track financial information which includes both bills that have been paid and bills that have been promised to be paid. I need to separate the two and then be able to add them back together. I am trying to use an if then else that looks like this...
Dim curPaidTotal as Currency
Dim curPromisedTotal as Currency

If chkDev(Tuition) = yes then
Dev(Tuition) + curPaidTotal
else
Dev(Tuition) + curPromisedTotal
end

if chkDev(Books) = yes then
Dev(Books) + curPaidTotal
else
Dev(Books) + curPromisedTotal
end

I have the code as an on open event
it's not working at all

can anyone help me

I've been back and forth about if I should just do two separate forms and make them enter the information twice. And then have a separate report but I really want to make it as easy as possible for them.
 
Glenda,

The code you supplied would never even compile. The syntax for this
construct is:
If <criteria> Then
Else
End If

I assume chkDev() and Dev() are both arrays, and that Tuition is a numeric
variable that you've declared and initialised elsewhere.

As for the calculation, you have to assign the calculated value to
something.
If chkDev(Tuition) = True Then
SomeValue = Dev(Tuition) + curPaidTotal
Else
SomeValue = Dev(Tuition) + curPromisedTotal
End If

If chkDev(Books) = True Then
SomeOtherValue = Dev(Books) + curPaidTotal
Else
SomeOtherValue = Dev(Books) + curPromisedTotal
End If

Then you have to do something with these two calculated values. Where have
you put this code? You say it's in the Open event, but the Open event to
what - a form or report? And exactly what are you trying to accomplish?
(There may be a better way).

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Glenda said:
I have created a report to track financial information which includes both
bills that have been paid and bills that have been promised to be paid. I
need to separate the two and then be able to add them back together. I am
trying to use an if then else that looks like this...
Dim curPaidTotal as Currency
Dim curPromisedTotal as Currency

If chkDev(Tuition) = yes then
Dev(Tuition) + curPaidTotal
else
Dev(Tuition) + curPromisedTotal
end

if chkDev(Books) = yes then
Dev(Books) + curPaidTotal
else
Dev(Books) + curPromisedTotal
end

I have the code as an on open event
it's not working at all

can anyone help me

I've been back and forth about if I should just do two separate forms and
make them enter the information twice. And then have a separate report but
I really want to make it as easy as possible for them.
 
I think I almost understand what you're doing:
- you have a table where each record contains a payment for a number of
different items, e.g. tuition, books, etc.
- for each item you have a pair of fields, each, one is for a received
payment amount, the other is for a promised amount
- for each promised amount field you have a checkbox which indicates
whether the payment has not yet been made?
- you want to produce a report where the total amount received for each
type of payment includes the amount whether it is received or promised based
on the checkbox?

There is the 'immediate if' function which can be used in an expression,
like

totalTuition = totalTuition+ iif(chkTuition=true, paidTuition,
promisedTuition)

Or in the query grid you put an expression like:

iif(chkTuition=true, paidTuition, promisedTuition)

then make it an aggregate query and sum these up.

Does this help?

Doug



Glenda said:
I have created database to track financial information. It is due on July
1st. on Thursday they told me they not only need to track what has been
paid but also what they have promised to pay. I added a checkbox to
correspond with all of my fields to enter different amounts. I did not want
them to have to enter the same info twice.
I added the checkboxes to a form which feeds a table called Payments. My
report is based on a parameter query that prompts for the Fiscal Year,
Semester and Funding Source. I thought I could just do code instead of
doing duplicate information. I'm knew to doing things past the Wizards in
Access but I've studied other languages and thought I could do it.
I've come to the conclusion that free lance stuff may not be forme. I
appreciate any suggestions you have.
 
Are you there Glenda?

We're waiting to see if Doug's suggestion has helped.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


Glenda said:
I have created database to track financial information. It is due on July
1st. on Thursday they told me they not only need to track what has been
paid but also what they have promised to pay. I added a checkbox to
correspond with all of my fields to enter different amounts. I did not want
them to have to enter the same info twice.
I added the checkboxes to a form which feeds a table called Payments. My
report is based on a parameter query that prompts for the Fiscal Year,
Semester and Funding Source. I thought I could just do code instead of
doing duplicate information. I'm knew to doing things past the Wizards in
Access but I've studied other languages and thought I could do it.
I've come to the conclusion that free lance stuff may not be forme. I
appreciate any suggestions you have.
 
Back
Top