This is the code it uses.
Public Function CalcUnitPrice(pdblPrice As Double, pstrSize As String, plngSectionCode As Long, pintErrorMessage As Integer, pintEquivalentTo As Integer) As String
Dim dbProm As Database, recSectionException As Recordset
Dim fdbPromOpen As Integer, frecSectionExceptionOpen As Integer
Dim intUnitConversion As Integer
Dim intUnitPosition As Integer
Dim intMultiplierPosition As Integer
Dim intX As Integer
Dim intY As Integer
Dim strQuantity As String
Dim strQuantityPart1 As String
Dim strQuantityPart2 As String
Dim strRestofSize As String
Dim dblQuantity As Double
Dim dblQuantityMultiplier As Double
Dim dblUnitPrice As Double
Dim dblFraction As Double
On Error GoTo CalcUnitPrice_Err
CalcUnitPrice = Space(0)
If pdblPrice = 0 Then
' If pintErrorMessage Then
' CalcUnitPrice = "Price not specified"
' End If
GoTo CalcUnitPrice_Done
End If
If Len(pstrSize) = 0 Then
If pintErrorMessage Then
CalcUnitPrice = "Actual Size not specified"
End If
GoTo CalcUnitPrice_Done
End If
If plngSectionCode = 0 Then
If pintErrorMessage Then
CalcUnitPrice = "Section not specified"
End If
GoTo CalcUnitPrice_Done
End If
'**** find old unit in actual size
intUnitPosition = 0
intUnitConversion = 0
Do Until intUnitConversion > glngUnitConversionCount Or intUnitPosition > 0
intUnitPosition = InStr(1, pstrSize, gstrOldUnit(intUnitConversion), vbTextCompare)
If intUnitPosition = 0 Then
intUnitConversion = intUnitConversion + 1
End If
Loop
If intUnitPosition = 0 Then
If pintErrorMessage Then
CalcUnitPrice = "Invalid Source Unit"
End If
GoTo CalcUnitPrice_Done
End If
'**** check for double weight
strRestofSize = Mid(pstrSize, intUnitPosition + Len(gstrOldUnit(intUnitConversion)))
intX = 0
intY = 0
Do Until intY > glngUnitConversionCount
intX = InStr(1, strRestofSize, gstrOldUnit(intY), vbTextCompare)
If intX > 0 Then
If pintErrorMessage Then
CalcUnitPrice = "Invalid Source Unit"
End If
GoTo CalcUnitPrice_Done
End If
intY = intY + 1
Loop
'**** extract quantity from actual size
strQuantity = Mid(pstrSize, 1, intUnitPosition - 1)
If Len(strQuantity) = 0 Then
If gintQuantityRequired(intUnitConversion) Then
If pintErrorMessage Then
CalcUnitPrice = "Invalid Source Quantity"
End If
GoTo CalcUnitPrice_Done
End If
strQuantity = "1"
End If
intMultiplierPosition = InStr(1, strQuantity, "x", vbTextCompare)
If intMultiplierPosition > 0 Then
strQuantityPart1 = Trim(Mid(strQuantity, 1, intMultiplierPosition - 1))
strQuantityPart2 = Trim(Mid(strQuantity, intMultiplierPosition + 1, Len(strQuantity) - intMultiplierPosition))
Else
strQuantityPart1 = "1"
strQuantityPart2 = Trim(strQuantity)
End If
If Not IsNumeric(strQuantityPart1) Then
If pintErrorMessage Then
CalcUnitPrice = "Invalid Source Quantity"
End If
GoTo CalcUnitPrice_Done
End If
If Not IsNumeric(strQuantityPart2) Then
If pintErrorMessage Then
CalcUnitPrice = "Invalid Source Quantity"
End If
GoTo CalcUnitPrice_Done
End If
dblQuantity = Val(strQuantityPart1) * Val(strQuantityPart2)
If dblQuantity = 0 Then
If pintErrorMessage Then
CalcUnitPrice = "Invalid Source Quantity"
End If
GoTo CalcUnitPrice_Done
End If
dblQuantity = dblQuantity * gdblMultiplier(intUnitConversion)
dblQuantityMultiplier = 1 / dblQuantity
'**** Apply Section Exceptions
dblUnitPrice = pdblPrice * dblQuantityMultiplier
Set dbProm = DBEngine.Workspaces(0).Databases(0)
fdbPromOpen = True
gdblSectionCode = plngSectionCode
gstrUnit = gstrNewUnit(intUnitConversion)
Set recSectionException = dbProm.OpenRecordset("qrytblSectionException", DB_OPEN_DYNASET)
frecSectionExceptionOpen = True
If Not recSectionException.EOF Then
gstrUnit = recSectionException!NewUnitDescription
dblUnitPrice = dblUnitPrice * recSectionException!Multiplier
Else
gstrUnit = "per " & gstrUnit
End If
'**** build unit price string
If dblUnitPrice >= 100 Then
dblFraction = dblUnitPrice - Int(dblUnitPrice)
dblFraction = dblFraction + 0.001
If dblFraction < 0.5 Then
gstrUnit = Format((dblUnitPrice / 100), "£0.00 ") & gstrUnit
Else
gstrUnit = Format((dblUnitPrice / 100) + 0.0005, "£0.00 ") & gstrUnit
End If
Else
If Val(Format(dblUnitPrice, "#")) = Val(Format(dblUnitPrice, "#.#")) Then
If (dblUnitPrice - Int(dblUnitPrice)) < 0.5 Then
gstrUnit = Format(dblUnitPrice, "#") & "p " & gstrUnit
Else
gstrUnit = Format(dblUnitPrice + 0.05, "#") & "p " & gstrUnit
End If
Else
If (dblUnitPrice - (Int(dblUnitPrice * 10) / 10)) < 0.5 Then
gstrUnit = Format(dblUnitPrice, "#.#") & "p " & gstrUnit
Else
gstrUnit = Format(dblUnitPrice + 0.005, "#.#") & "p " & gstrUnit
End If
End If
End If
If pintEquivalentTo Then
gstrUnit = "Equivalent To " & gstrUnit
End If
If pintErrorMessage Then
CalcUnitPrice = Space(0)
Else
CalcUnitPrice = gstrUnit
End If
CalcUnitPrice_Done:
On Error GoTo 0
If frecSectionExceptionOpen Then
recSectionException.Close
End If
If fdbPromOpen Then
dbProm.Close
End If
Exit Function
CalcUnitPrice_Err:
Select Case Err
'Handle specific errors
Case Else: MsgBox "Error " & Err & " " & Error(Err)
End Select
Resume CalcUnitPrice_Done
End Function
It is not just an Access 2000 problem. It has happened on a Test db that we use for enhancements. Don't know how we got round that problem.