I am extracting data from external data base into a query. I have a field
for Catergory which pulls numbers 1,2,3. I need to change them to Roman
numbers I, II, III in order to work with my classification.
I can't figure out a way to accomplish that in access 2003.
Can someone help?
I found this from long, long ago... see if it works for you.
Public Function Roman(ByVal intIn As Long) As String
Dim Unit As Variant
Dim Five As Variant
Unit = Array("I", "X", "C", "M", "Xbar", "Cbar", "Mbar")
Five = Array("", "V", "D", "L", "Vbar", "Dbar", "Lbar")
Dim iDigit As Integer
If intIn < 0 Then
Roman = "-"
intIn = Abs(intIn)
Else
Roman = ""
End If
If intIn > 4000000 Then
Roman = Roman & "<number too large>"
Exit Function
End If
For iDigit = 6 To 1 Step -1
Do While intIn >= 10 ^ iDigit
Roman = Roman & Unit(iDigit)
intIn = intIn - 10 ^ iDigit
Loop
If intIn >= 9 * 10 ^ (iDigit - 1) Then
Roman = Roman & Unit(iDigit - 1) & Unit(iDigit)
intIn = intIn - 9 * 10 ^ (iDigit - 1)
End If
If intIn >= 5 * 10 ^ (iDigit - 1) Then
Roman = Roman & Five(iDigit)
intIn = intIn - 5 * 10 ^ (iDigit - 1)
End If
If intIn >= 4 * 10 ^ (iDigit - 1) Then
Roman = Roman & Unit(iDigit - 1) & Five(iDigit)
intIn = intIn - 4 * 10 ^ (iDigit - 1)
End If
Do While intIn >= 10 ^ (iDigit - 1)
Roman = Roman & Unit(iDigit - 1)
intIn = intIn - 10 ^ (iDigit - 1)
Loop
Next iDigit
End Function
Sample results:
?roman(13)
XIII
?roman(32768)
XbarXbarXbarMMLCCDXVIII
?roman(3999999)
MbarMbarMbarCbarMbarXbarCbarMXbarCMXCIX
John W. Vinson [MVP]