From your database window, select Modules. Then click New. This will open
the VBA editor. Copy and paste the function from "Function Get..."
through
"End Function" into the window. Then click the save icon to save your
module with the name "modCalcs". Then press Ctrl+G to open the
immediate/debug window. You can test your function by typing in:
+----------------
|? GetQty("KT/100 BX/200 ST/1000")
|
Pressing enter on the above line should return a result of 20000000.
You can then use this function in queries, code, control sources,... like
GetQty([PackagingString])
where PackagingString is the name of your field.
Function GetQty(pstrPkg As String) As Long
Dim lngOut As Long
lngOut = 1
Dim intLen As Integer
Dim intChar As Integer 'which character to examine
Dim intNum As Integer 'found number in string
intLen = Len(pstrPkg)
For intChar = 1 To intLen
If IsNumeric(Mid(pstrPkg, intChar, 1)) Then
'get the value of the found number
intNum = Val(Mid(pstrPkg, intChar))
'multiply the values
lngOut = lngOut * intNum
'skip characters to a non-numeric
intChar = intChar + Len(Trim(Str(intNum)))
End If
Next
GetQty = lngOut
End Function
--
Duane Hookom
MS Access MVP
Duane,
Sorry, I did not respond, Honesty I could not remember if I asked the
question or not. So yes, creating the function is what I need help
with.
Would you mind helping me out with this? Or, is it something that can
not
be
done on a message board more in person?
--
Thomas
:
I answered this same question for you Oct 24th
http://groups.google.com/group/micr...f1da9?lnk=st&q=&rnum=1&hl=en#0d58ceb0704f1da9
You didn't reply. Do you need assistance with creating a function?
--
Duane Hookom
MS Access MVP
OK, I have some sample data, not real good with IF statements in
Access,
Need
to know if it can be done with the reult I need and how the iIF
statement
looks. If this can be done, thank you in advance for the help.
PackagingString Result
EA 1
CS/12 EA 12
CS/20 PK/4 EA 80
CS/20 PK/40 EA 800
CS/4 EA 4
CS/100 EA 100
BX/1000 EA 1000
KT/1 PK/100 EA 100
KT/1 BX/2 ST/1 EA 2
KT/10 BX/20 ST/10 EA 200
KT/100 BX/200 ST/1000 EA 200000
CS/10 BX/100 EA 1000
CS/10 PK/1000 EA 10000
CS/100 PK/1000 EA 100000
CS/1000 PK/1000 EA 1000000