I have created a function in the VBA code so that when a string is passed, it will return a number:
Right the problems I am facing... I have to put the rVal numbers into quotes "" because for numbers like 2.50 VBA turns them into 2.5. The number 4.00 gets turned into 4# (very annoying).
I want the number to be returned to my query as a 2 decimal place number - even if it has any 0s after the DP. When I use the FormatNumber(FN _Test('4'), 2) in my query, this bizzarely gets turned into a String so that when I want to add the value to another value, they get concatenated as strings.
If anybody has any idea what I am trying to do and can help, please let me know. I will answer as many questions as I can if you think it will help. Would also appreciate alternative solutions!
Matthew
Code:
Public Function FN_Test(ByVal LT1 As String) As Single Dim rVal As Single Select Case LT1 Case "W": rVal = "0.78" Case "1": rVal = "1.66" Case "L": rVal = "1.66" Case "X": rVal = "1.66" Case "2C": rVal = "2.17" Case "2B": rVal = "2.50" Case "2": rVal = "2.50" Case "2A": rVal = "2.83" Case "3": rVal = "3.32" Case "4": rVal = "4.00" Case Else: rVal = Null End Select FN_Test = rVal
I want the number to be returned to my query as a 2 decimal place number - even if it has any 0s after the DP. When I use the FormatNumber(FN _Test('4'), 2) in my query, this bizzarely gets turned into a String so that when I want to add the value to another value, they get concatenated as strings.
If anybody has any idea what I am trying to do and can help, please let me know. I will answer as many questions as I can if you think it will help. Would also appreciate alternative solutions!
Matthew
Comment