Hi Crystal,
I made a couple of changes to make the "Compile Error. in Query Expression
ConvertInchStringtoMmString([SideA])" message. It was a pop-up window with
only the OK or Help buttons. I wasn't getting the debbuging window. Here's my
progress but now I am stuck with two items.
1. If the field value is null, the query result is #Error instead of a null
value.
2. The query gets stuck when the field value is "171-173". You will notice
that I included the "." and the "-" as part of the numeric field so values
with the decimal point and/or a negative value are computed. The reason for
this is that I am trying to make a temperature computation in another field.
Therefore the negative value is important (I never realized this before).
Thank you for pointing out the backslash use, I wasn't aware of it.
Function ConvertInchStringtoMmString(pinchString As String) As String
Dim mBefore As String, mAfter As String, _
mNumStr As String, mBoo As Boolean, i As Integer
mBefore = ""
mAfter = ""
mBoo = False
mNumStr = ""
For i = 1 To Len(Nz(pinchString))
If IsNumeric(Mid(pinchString, i, 1)) Or Mid(pinchString, i, 1)="." Or _
Mid(pinchString, i, 1)="-" Then
mBoo = True
mNumStr = mNumStr & Mid(pinchString, i, 1)
Else
If mBoo = True Then 'modified
mAfter = mAfter & Mid(pinchString, i, 1)
Else
mBefore = mBefore & Mid(pinchString, i, 1)
End If
End If
Next i
ConvertInchStringtoMmString = mBefore &_
CStr(FormatNumber((Val(mNumStr)/25.4),2)) & mAfter
End Function
:
compiling code
---
Hi Martin,
you're welcome
I see one problem... there may be more, but this one jumped out
ConvertInchStringtoMmString = mBefore &_
needs to be
ConvertInchStringtoMmString = mBefore & _
when using _ to continue a statement across lines, you must have SPACE
UNDERSCORE, not just underscore
when you compile, which line receives an error?
'~~~~~~~~~ Compile ~~~~~~~~~
Whenever you change code or references, your should always compile
before executing.
from the menu in a module window: Debug, Compile
fix any errors on the yellow highlighted lines
keep compiling until nothing happens (this is good!)
~~~
I had used
mNumStr\25.4
instead of
mNumStr/25.4
so you would get the numeric result as a whole number ...
I suppose it could be griping because you are actually dividing a string
instead of a number... try this:
Val(mNumStr) instead of just mNumStr
Warm Regards,
Crystal
*

have an awesome day

*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
Martin wrote:
Hi Crystal,
Thanks for your response. I forgot to check for automatic replies and I
forgot where I posted the question. Your response is masterful for what I
need. However, I am getting a compile error when running the query. I did a
couple of modifications since I believe you forgot some...here's what I have
in my Module which I called it Conversion...
Function ConvertInchStringtoMmString(pinchString As Text) As Text
Dim mBefore As Text, mAfter As Text, _
mNumStr As String, mBoo As Boolean, i As Integer
mBefore = ""
mAfter = ""
mBoo = False
mNumStr = ""
For i = 1 To Len(Nz(pinchString))
If IsNumeric(Mid(pinchString, i, 1)) Then 'modified
mBoo = True
mNumStr = mNumStr & Mid(pinchString, i, 1)
Else
If mBoo = True Then 'modified
mAfter = mAfter & Mid(pinchString, i, 1)
Else
mBefore = mBefore & Mid(pinchString, i, 1)
End If
End If
Next i
ConvertInchStringtoMmString = mBefore &_
(mNumStr/25.4) & mAfter 'Modified
End Function
In my Query I have the table with the field, and in one column I used
SideAMM:ConvertInchStringtoMmString([SideA])
Thanks for the help!
:
convertInchStringToMmString
---
Hi Martin,
you can write a function to return the desired results
put this into a general module:
'~~~~~~~~~~~~~~
Function convertInchStringToMmString(pInchString as text)
dim mBefore as text _
, mAfter as Text _
, mNumStr as String _
, mBoo as boolean
, i as integer
mBefore = ""
mAfter = ""
mBoo = false
mNumStr = ""
for i = 1 to len(nz(pInchString,""))
if isnumeric(pInchString) then
mBoo = true
mNumStr = mNumStr & mid(pInchString, i, 1)
else
if mBoo then
mAfter = mAfter & mid(pInchString, i, 1)
else
mBefore = mBefore & mid(pInchString, i, 1)
end if
end if
next i
convertInchStringToMmString = mBefore _
& mNumStr\25.4 _
& mAfter
End Function
'~~~~~~~~~~~~~~
then, in a query, you can see the reulsts by creating a claculated column:
ColumnName: convertIncheStringToMmString([fieldname])
where
ColumnName is what you want to call the column (cannot be the same as a
fieldname in the recordsource)
[fieldname] is the name of the field you want to convert