How can I pull only the number from a field and put that value into its own field?
For example, if a field1 contains a value of "Name(1234U)".
I need an SQL or VBA way to scan that field and pull the number out. So field2 will equal "1234".
Any ideas?
Create a VBA function, call it as a field in your query and pass it the original field (like
select GetNumerals(field1) from table...
). The VBA function will loop through each letter in the field and return only the numeric values. It could look something like this:It is possible that this or a variation may suit:
For example:
EDIT re comment
If the field ends
u)
, that is, alpha bracket, you can say:The following VBA function might do the trick:
Example using the regular expression pattern
which matches one or more non-digit characters
returns
edit:
To use this in a query run from within the Access application itself, try something like