ms-access


Removing certain strings in an Access 2010 query


I currently have an Access query that returns data in two forms
One form is 5 numbers, e.g., 12345
The other form is 2 letters, followed by 5 numbers, e.g., ab12345
This is coming in the same field, and I need to get only the numbers. I can't strip off the first two characters, because then for the IDs that have only the numbers, I'm cutting it short.
Use Val(string) to strip letters after numbers.
Use pVal(string) to strip letters before numbers.
string1 = "123456abcd1234"
val1 = val(string1) => val1 = 123456
string2 = "aqweqweasd123456abcd1234"
val2 = pval(string2) => val2 = 123456
if in case you have "asdasd123asasd456" and you want to have 123456 as result you can modify the pval to replace all non numeric values from output
here is the pVal function. Place this in a module and use it from anywhere
Public Function pVal(s As String)
Dim i As Long
For i = 1 To Len(s)
If IsNumeric(Mid(s, i, 1)) Then
pVal = Val(Mid(s, i, Len(s)))
Exit Function
End If
Next i
End Function
Use a select query as source for your form like this with an expression that strips the two leading characters:
Select *, Mid([XX0000NumberField], 3) As NumberOnlyID
From YourTable
Or for mixed numbers:
Select *, Right([XX0000NumberField], 5) As NumberOnlyID
From YourTable

Related Links

Code or the control properties, which is better in MS-ACCESS?
Changing The Data Type from Float to?
Connection to Oracle via VBScript
Is there a way to submit an InfoPath form to an Access database if the form was designed first?
Copying a record in VBA 2 (the new question)
Access 2007 DAO VBA Error 3381 causes objects in calling methods to “break”
ms access reports and queries
Passing variables from child to master form
Query to find the running sum of a column(qty) based on type(if 'a' add else subtract)
Can't create blank form in MS Access
How to give where condition in the select query?
What is the order of form/report events in MS Access?
moving focus from subform to main form
Alternative for Report.Load() event in Ms Access 2003
defining delimiters in vba for access
how to check if subform is opened in ms access

Categories

HOME
clips
cloud
zeromq
image-processing
smarty
homebrew
appx
include
react-redux
cmd
leon
sharepoint-designer
v8
pivotal-cloud-foundry
acquia
datastax-java-driver
node-notifier
cross-validation
dacpac
facebook-php-sdk
metatrader4
export-to-csv
nstableview
carthage
quartz-scheduler
telephony
pc
google-static-maps
solaris-10
http-status-code-504
beyondcompare
scichart
riot.js
functional-testing
sox
dcevm
mmap
one-to-many
cas
underflow
facet
facebook-access-token
minitab
facebook-apps
libuv
gsoap
bcd
binary-data
semantic-versioning
jspresso
code-contracts
textmate
sequential
bytecode-manipulation
withings
sharefile
avro4s
fedex
password-encryption
arena-simulation
unixodbc
node-sass
azure-application-gateway
hibernate-tools
apache-fop
hendrix
nstextview
jxcore
imanage
dwscript
google-cdn
messenger
visual-c++-2008
elements
google-web-starter-kit
fuzzy-search
holder.js
disque
qcustomplot
python-stackless
ptrace
xpath-1.0
vhd
msys
eclipse-clp
retina
feedback
pundit
angular-leaflet-directive
map-projections
census
notify
formatjs
fscommand
qpainter
codeigniter-url
mesa
fluentautomation
expected-exception
valuechangelistener
undefined-reference
android-2.2-froyo
java.nio.file
ivyde
commoncrypto
jmapviewer
web2py-modules
eclipse-memory-analyzer
jquery-mobile-dialog
pygit2
jelly
datawindow
adk
gnu-prolog
doh
gcj
psi
pyinotify
radcombobox
gallio
forums
virtual-functions
noscript
sector
.net-1.0

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App