Grade Payment

  • Thread starter Thread starter Tim Eagle
  • Start date Start date
T

Tim Eagle

I have a database and I want to calculate something on my report. It's a
grade database that pulls on the form a grade from a marking period and I
want each grade to autofill, on the form, a payment for that particular
grade. For example A = $7.00 and B=$5.00, what type of box would I create to
get this result? If you need more information please let me know. Thanks.

Tim Eagle
http://www.timeagle.com
 
I'm sorry, just a little tired. I have a report, The following fields come
from a query and apear on my report: [Grade], [marking period], etc. The
[Grade] field is either A, B, C, D, or E. I would like to know the code to
create a calculation of each letter grade, fro example A=$7.00, or if
B=$5.00 I'm sure there is a code, I have used something like it before. I'm
not a complete novice, just a person that don't sit all day creating
databases and running code. I know the basics well, I appreciate any help
that anyone can give me. It's been a long time that I've posted on this that
I forgot how detailed the posts need to be to get good feedback and accurate
code. Thanks again, and sorry for my ignorance previously.

Tim Eagle
 
Which is it, a Form or a Report? If they seem like the same thing to
you then you need to develop familiarity with the correct nomenclature
for at least the most common user interface elements in Access.

For novices with Access I always recommend lurking in another couple
of newsgroups as sell.

microsoft.public.access..gettingstarted
microsoft.public.access..tablesdesign

Also, visit www.mvps.org/access It's an incredibly valuable resource
to Access developers.

HTH
 
I have a database and I want to calculate something on my report. It's a
grade database that pulls on the form a grade from a marking period and I
want each grade to autofill, on the form, a payment for that particular
grade. For example A = $7.00 and B=$5.00, what type of box would I create to
get this result? If you need more information please let me know. Thanks.

Two suggestions:

1. Preferred, as Aaron suggests: create a two-field table with a text
field Grade and a currency field Payment; fill it with one row for
each grade letter. Join it to your Query.

2. Less ideal, as it's harder to maintain: use a Switch() function:

Payment: Switch([Grade] = "A", CCur(7.0), [Grade] = "B", CCur(5.0),
[Grade] = "C", CCur(3.0), [Grade] = "D", CCur(1.0), [Grade] = "F",
CCur(0.), True, Null)

John W. Vinson[MVP]
 
To keep life simple, create another table: tblGradePay which will list
just the Letter grade and its value. GradeName, Text and GradeValue,
Currency (or a datatype your version supports)

Include tblGradePay in your query and alter your Report's design to
accommodate the new fields; datasources correctly.

FWIW it's common practice to answer the correct post in the thread.
That way, the thread can have branches and wiggles but each thread
will track correctly.

HTH
--
-Larry-
--

Tim Eagle said:
I'm sorry, just a little tired. I have a report, The following fields come
from a query and apear on my report: [Grade], [marking period], etc. The
[Grade] field is either A, B, C, D, or E. I would like to know the code to
create a calculation of each letter grade, fro example A=$7.00, or if
B=$5.00 I'm sure there is a code, I have used something like it before. I'm
not a complete novice, just a person that don't sit all day creating
databases and running code. I know the basics well, I appreciate any help
that anyone can give me. It's been a long time that I've posted on this that
I forgot how detailed the posts need to be to get good feedback and accurate
code. Thanks again, and sorry for my ignorance previously.

Tim Eagle

Tim Eagle said:
I have a database and I want to calculate something on my report. It's a
grade database that pulls on the form a grade from a marking period and I
want each grade to autofill, on the form, a payment for that particular
grade. For example A = $7.00 and B=$5.00, what type of box would I create
to get this result? If you need more information please let me know.
Thanks.

Tim Eagle
http://www.timeagle.com
 
Just another thought to add to Larry's and John's good ones ...

If you add the module below to your app, you can call the grade payment as
the comment in the code indicates. This will save adding a table and
connecting it each time you build a query (first suggestion). And it will
save you adding longer code each time you want to use the value (second
suggestion). Both other suggestions will work just fine, but I thought you
might like to consider one more idea. Of course, you will have to change the
module values if they change, but only in one place.


Public Function GradePay(GradeIn As String) As Currency

' To use this function call it as GradePay(NZ([Grade],"X")) in a report,
' query or form, where [Grade] is your field name (change as appropriate).
' The NZ part accommodates nulls and the Else in code picks up any other
entries.

Select Case GradeIn
Case "A"
GradePay = 7
Case "B"
GradePay = 5
Case "C"
GradePay = 3
Case "D"
GradePay = 1
Case "F"
GradePay = 0
Case Else
GradePay = 0
End Select

End Function
 
Payment: CCur(Switch([Grade] = "A", 7, [Grade] = "B", 5,
[Grade] = "C", 3, [Grade] = "D", 1, [Grade] = "F",
0, True, Null))

and technically; he was using the grade 'E' and not the grade F right?

Payment: CCur(Switch([Grade] = "A", 7, [Grade] = "B", 5,
[Grade] = "C", 3, [Grade] = "D", 1, [Grade] = "E",
0, True, Null))

or you could make a function like this; paste this in a new module

Public Function GetGradeDollarValue(strGrade as string) as Currency

Dim cOut as Integer
Select Case strGrade
Case "A"
cOut = 7
Case "B"
cOut = 5
Case "C"
cOut = 3
Case "D"
cOut = 1
Case "E"
cOut = 0
Case Else
cOut = 0

End Select

GradeDollarValue = CCur(cOut)

End Function


And then you could just consume this function in expression builder for
example.

Or; if you were using Access Data Projects-- which are truly the best /
cheapest way to do *anything* then you could juse write a similiar UDF
like this

Create Function dbo.GetGradeDollarValue(
@strGrade as string
)
Returns Money

AS
BEGIN

DECLARE @cOut INTEGER

SET @cOut = Case @strGrade
When "A" Then 7
When "B" Then 5
When "C" Then 3
When "D" Then 1
When "E" Then 0
Else 0
END

RETURN CAST @cOut AS MONEY

End Function


Please forgive me if the syntax is off a little bit; I'm a QBE guy and
I just LOVE the query designer in Access.

The ability to write sprocs and views in design view-- is a feat that
is very very friendly; and it's an enterprise level database system.
For example; you could write the function once and then utilize it
through any function; instead of needing to rewrite it, or copy / paste
it every app you need it.

-Aaron

John said:
I have a database and I want to calculate something on my report. It's a
grade database that pulls on the form a grade from a marking period and I
want each grade to autofill, on the form, a payment for that particular
grade. For example A = $7.00 and B=$5.00, what type of box would I create to
get this result? If you need more information please let me know. Thanks.

Two suggestions:

1. Preferred, as Aaron suggests: create a two-field table with a text
field Grade and a currency field Payment; fill it with one row for
each grade letter. Join it to your Query.

2. Less ideal, as it's harder to maintain: use a Switch() function:

Payment: Switch([Grade] = "A", CCur(7.0), [Grade] = "B", CCur(5.0),
[Grade] = "C", CCur(3.0), [Grade] = "D", CCur(1.0), [Grade] = "F",
CCur(0.), True, Null)

John W. Vinson[MVP]
 
Hi Jim,

The flaw with your solution is that values are "hard wired". To
change the value of "A" your code would have to be opened and the
value changed in code (even using constants in your routine would be
better than your example. Users shouldn't be required to do that.
Having users open your code is an invitation to disaster.

Alternatively, your life may become plagued with endless calls from
your users/bosses to change the values.

The table solutions are amenable to change by users: Create
maintenance forms for your lookup tables that enable users to open the
form, find the Grade and change the associated value.

HTH
--
-Larry-
--

Joe D said:
Just another thought to add to Larry's and John's good ones ...

If you add the module below to your app, you can call the grade payment as
the comment in the code indicates. This will save adding a table and
connecting it each time you build a query (first suggestion). And it will
save you adding longer code each time you want to use the value (second
suggestion). Both other suggestions will work just fine, but I thought you
might like to consider one more idea. Of course, you will have to change the
module values if they change, but only in one place.


Public Function GradePay(GradeIn As String) As Currency

' To use this function call it as GradePay(NZ([Grade],"X")) in a report,
' query or form, where [Grade] is your field name (change as appropriate).
' The NZ part accommodates nulls and the Else in code picks up any other
entries.

Select Case GradeIn
Case "A"
GradePay = 7
Case "B"
GradePay = 5
Case "C"
GradePay = 3
Case "D"
GradePay = 1
Case "F"
GradePay = 0
Case Else
GradePay = 0
End Select

End Function

Tim Eagle said:
I have a database and I want to calculate something on my report. It's a
grade database that pulls on the form a grade from a marking period and I
want each grade to autofill, on the form, a payment for that particular
grade. For example A = $7.00 and B=$5.00, what type of box would I create to
get this result? If you need more information please let me know. Thanks.

Tim Eagle
http://www.timeagle.com
 

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

Back
Top