Ok - try this:
1. Create a Function in your VBA Editor - like this:
Code:
Function CountCommas(Cert_OTR As String) As Integer
CountCommas = 5
End Function
In your Query design view - create a new field like this:
Commas: CountCommas([Cert_OTR])
Run the Query & you'll see a 5 in every row of the Comma field. That's because the function is not counting anything yet. It is just returning the number 5 to the query.
That is just to give you the framework of how the query & Function work together.
Next, you can DO something with the Cert_OTR string that your Query passes to the Function:
Code:
Function CountCommas(Cert_OTR As String) As IntegerDim intPos As Integer, intPos2 as Integer, intCount as Integer
intPos1 = 1
intPos2 = InStr(intPos1, Cert_OTR, ",")
CountCommas = intPos
End Function
What you'll get from that is the position of the first comma in the string [if there is a comma].
Finally, you will need to add code to do a few other things in a loop:
You could create a
Do While intPos > 0
'put all your code in here.
'when there are no commas - the InStr function returns 0.
Loop
1. Determine if there is anything at all in the string you are passing [use the Len() VBA function]. If so - set a 'counter' variable to 1.
2. If there IS text in there - but you don't find a comma - does that mean there is only one value in the field? If so do a CountCommas = 1.
3. If you DO find a comma:
a. Increment the comma-counter.
b. Increment intPos by 1 [intPos + 1]
c. Loop around to run the InStr function again . . .
Hope this helps get you started - but let us know if you need more help!!
This is just meant to give you something to start off with . . .
All the Best