Hi vanguardaccessman,
Try this to see if it works for you. First, create a new stand-alone module
and paste the code shown below into it:
___________________________
Option Compare Database
Option Explicit
Public Function DetermineResult(Mark As Variant) As Variant
On Error Resume Next
If Len(Mark & "") > 0 Then
Select Case Mark
Case "P", "F"
DetermineResult = Mark
Case "0"
DetermineResult = 0.5
Case IsNumeric(Mark) = True
Mark = CCur(Mark)
Select Case Mark
Case 0 To 64
DetermineResult = 0.5
Case 65 To 95
DetermineResult = Format(([Mark] - 55) / 10, "0.0")
Case 96 To 100
DetermineResult = Format(4, "0.0")
Case Else
DetermineResult = "Out of range."
End Select
Case Else
DetermineResult = "Out of range."
End Select
End If
End Function
___________________________
Name this module something like basCalculateResult (the important point
being to give your module a unique name that is not already the name of an
existing subroutine or function, and is not a reserved word). Compile the
code by clicking on
Debug > Compile {ProjectName}
where {ProjectName} is the name of your VBA project. Your code should
compile without any errors.
Create a new query. Dismiss the Add Tables dialog without adding any tables.
In query design view, click on View > SQL View. You should see the word
SELECT highlighted. Delete this default keyword. Copy the following SQL
statement (Ctrl C) and paste it into the SQL view (Ctrl V), replacing the
SELECT keyword:
SELECT [Mark], DetermineResult([Mark]) AS vangrade
FROM [tblMarks];
Note: You didn't give the name of your table, so I used a name of
"tblMarks". Make the appropriate substitution in the above SQL statement. You
can then switch back to the more familiar design view, if you wish, by
clicking on View > Design View. Run the query. Does this provide the results
you were looking for?
Tom Wickerath
Microsoft Access MVP
http://www.accessmvp.com/TWickerath/
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
vanguardaccess said:
I have a field, called [Mark], that can be anywhere from 0 to 100. I would
like a query field, called [vangrade], to operate the following on the number:
If [Mark] is from 0 to 64, change to 0.5
If [Mark] is from 65 to 95, apply the formula ([Mark]-55)/10
If [Mark] is from 96-100, change to 4.0
As a secondary question, besides being anywhere from 1-100, [Mark] can also
be a P or an F. Is it possible to have the P or F just stay as they are in
[vangrade] while performing the calculation above? If so, how?
Thanks,
--vanguardaccessman