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

How to enable 1 user to update the database while allowing others to only read in Microsoft Access?
Operation is not allowed when the object is open
Single prompt parameter for shared parameter in sub-reports' queries
Don't show corresponding field items
VBA traversing through recordset via button
Add new Items in a combo box in access
Generate an ID from different column choices in Microsoft Access 2013
MSACCESS query: not part of an aggregate function
pdi spoon ms-access concat
iff command issue in MS Access
How to display the maximum value from one column in a listbox, in a textbox on the same form
access 2010 writing SQL statements
Add Working Days to Start Date to Create End Date (including Bank Holiday)
ms access input mask MM/DD/YYYY
'Microsoft.ACE.OLEDB.12.0' provider is not registered -but it is
How do I run this query?

Categories

HOME
listview
path-finding
google-api-php-client
relative-path
stock
session
electron
mean-stack
amortized-analysis
ravendb
echarts
cloudkit
facebook-php-sdk
gnupg
vifm
ssl-client-authentication
moonmail
visual-studio-2005
decomposition
decimal
libtiff
scriptcs
jasonette
intentfilter
php-openssl
microsoft-r
crystal-reports-2010
phpfox
minitab
dbclient
functor
azure-sql-database
atl
google-api-nodejs-client
plsql-psp
git-merge
abstract-class
xenforo
sas-visual-analytics
hp-ux
mapzen
galen
checkboxlist
gpx
segment
apache-fop
jedis
worksheet
drupal-6
composite-key
snmptrapd
pdfclown
flow-control
mcafee
word-vba-mac
passport-google-oauth
rotativa
log4c
storekit
connect-by
ubuntu-10.04
ios4
rhino-servicebus
execute
rgeo
p2
typekit
ng-animate
openexr
didselectrowatindexpath
geos
xsockets.net
cdc
ora-00911
simba
sublist
javaspaces
dbproviderfactories
transactionscope
fireworks
mod-auth
gdlib
html-input
cxxtest
getresponsestream
firefox4
avatar
privilege
3gp
lzh

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