Thanks,
Wow, your programming looks like poetry when compared to my sloppy slog.. Yes I am using Access 2000 so your code works like a dream. Except that the split function doesn't always work as the 6 digits sometimes do not have a space on either side. I have the following, which seems to get around this, but are struggling to get it to work :
Public Function eOrderLookup(inputText) As String
'Purpose: find six digits (numercial values) in row and returns them.
'Arguments: text field for function to look up.
'Author: Marcus.
'Examples:
'1. To find the eorder in the text, e.g.:
' EOrderLookup("B1 INV785574 26/03/04")
' Returns: "785574"
Dim myCheck As String
Dim x As Integer
Dim y As Integer
Dim myEOrder As String
For x = 1 To Len(inputText)
myCheck = ""
For y = 0 To 5
myCheck = myCheck & IsNumeric(Mid(inputText, x + y, 1))
If myCheck = "TrueTrueTrueTrueTrueTrue" Then
myEOrder = Mid(inputText, x, 6) ' 6 numeric fields in a row!
eOrderLookup = myEOrder
End
End If
Next y
Next x
eOrderLookup = myEOrder
End Function
This function works when I call an i test it:
Function Test()
Dim myText As String
myText = "B1 INV785574 26/03/04"
eOrderLookup myText
End Function
But if i add it to a query the i get the following error: "Undefined Function 'eOrderLookup' in expressoin"
I'm not sure why...
thanks again for you help
marcus.
John Spencer (MVP) said:
What version of ACCESS? With 2000 and later you could use the Split function.
UNTESTED AIRCODE follows
Public Function GetSix(StrIN) As String
Dim varObject As Variant
Dim iLoop As Integer
Dim strReturn As String
varObject = Split(StrIN, " ")
For iLoop = LBound(varObject) To UBound(varObject)
If varObject(iLoop) Like "######" Then
strReturn = varObject(iLoop)
Exit For
End If
Next iLoop
GetSix = strReturn
End Function
marcus. said:
Thanks Jeff,
I tried the val() function, but didn't have much luck, while it did calculate for a 'few' rows. The majority of the data returned with zeros.
Does anyone else have any ideas?
My thought is perhaps i should be writing a macro that checks the field character by character through a loop. If there is six characters in a row, then to return that value and move to the next filed, else leave a blank. But how to i set out to do this?
Thanks,
Marcus
Jeff Boyce said:
Marcus
Up until your last example,
INV 787676 30/3 RR
an option would have been to use the Val() function to return the numeric
value.
Given the possibility that more than one "set" of numbers may be in the text
string, Val([YourString]) isn't guaranteed to pick the correct set of
numbers.
Still, consider using Val() and inspecting the results to help you identify
which records you'd need to "manually" fix.
--
Good luck
Jeff Boyce
<Access MVP>