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

MS Access Query - Total Week Hours Worked
SQL Query to MS SQL - Parameter Value
Complex fill in the blanks query in MS Access 2010
Compile Error: User Type Not Defined - MS Access
MSAccess - Requery a Subform After Insert?
MS Access 2016 won't open an .accdb file because it 'was created in a previous version'. Is there a fix?
Export data from Access 2010 to Excel 2013
Access SQL query to match column data with row criteria and fetch score
Disabled Mode, Microsoft Access 2016
JavaFX : where to put portable database file for application
Importing Excel Data into Access Using Index - How to Prevent Popup Message
Include Microsoft Office Access database engine 2007 to installer with InstallShield Limited Edition
Create single report with multiple record data?
What do I gain from specifying relationships in my database?
Microsoft Access VBA: Button to Filter Report
Trying to pull data from text boxes on a form into a query and out to a table?

Categories

HOME
xamarin
jdo
deployment
image-processing
azure-data-factory
google-play
relayjs
jsp-tags
google-oauth
amortized-analysis
pivotal-cloud-foundry
indesign
ios-charts
applepay
elasticsearch-hadoop
facebook-php-sdk
modx-revolution
gz
remote-access
orchardcms
lombok
ef-migrations
facebook-page
pugjs
object-detection
physics-engine
graphicsmagick
realex-payments-api
trading
vlsi
buildbot
sparse-matrix
django-storage
filezilla
fluentvalidation
log4js-node
jspm
webkitspeechrecognition
subdomains
c++-amp
newline
instant-messaging
bluestacks
binary-data
http-get
main
hp-ux
websphere-mq-fte
rainbowtable
upstart
revapi
python-c-api
domain-model
composite-key
lift-json
r-forge
pearson
mediaelement
firmata
home-directory
skobbler-maps
autorest
jwplayer7
python-stackless
sdf
bluemix-app-scan
tform
javax.sound.midi
service-accounts
splash
apache-commons-net
javax.mail
nsmutabledictionary
openexr
mesa
comexception
mysql-error-1062
mechanize-ruby
mcts
c18
eventual-consistency
pushbackinputstream
yui-compressor
spring-validator
html-editor
wsdl-2.0
distutils
referrer
mhtml
nsnetservice
reddot
deobfuscation
recent-documents
sql-server-profiler
site.master
filtered-index
xetex
simpletest
text-coloring
procedural-music
putchar
geneva-server
multiple-languages
windows-live-messenger
caching-application-block

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