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 how to make footer for only front page
VBA Userform Path/File Access Error - Error 75
UNC-linked data in Access MDB is read-only
Stop Access from Auto assigning Datatypes
Validate password against its username in Access
SQL Update with 0 if no match
VB6 application and a protected access database
MS Access Table shown in query as Alias
MS Access - Identify highest 3 values across columns
Automatically populated Modified by table column - Access 2013
How do i reference a popup form in Access VBA
Hierarchical data searching
“operation is not supported for this type of object” ODBC error from running SQL pass through query
MS Access 2000 Chart
Create Lotus Notes entry from Access Event
Import csv file into an ms acces table- Data ignored [duplicate]

Categories

HOME
sendgrid
image-processing
single-sign-on
path-finding
onedrive
relay
octobercms
mean-stack
yarn
infragistics
yum
node-notifier
midi
php-7.1
alignment
vaadin7
dosgi
saxon
aurigma
scichart
predix
wijmo
angular2-aot
sqlcipher
buildbot
qhull
info.plist
windows-server-2000
srcset
fabric8
yadcf
protovis
jmonkeyengine
ios5
http-digest
bitbucket-pipelines
gesture
withings
greenrobot-eventbus
pdf-reactor
node-sass
qcombobox
auto-update
jsch
hibernate-tools
prolog-setof
multipeer-connectivity
boost-multi-index
yii2-extension
elgg
linode
nbconvert
jspdf-autotable
topbeat
vmware-tools
file-writing
intrusion-detection
fody
measures
etsy
autorest
bstr
lttng
disque
bluemix-app-scan
pyke
wireshark-dissector
sframe
ios9.1
interrupted-exception
angular-local-storage
proj4js
e10s
python-green
dia
camanjs
javafx-webengine
nsbutton
castle
funcunit
jboss-weld
resty-gwt
.aspxauth
aqtime
quartz-graphics
html4
mylyn
bluepill
dice
nsmanagedobject
code-cleanup
cinema-4d
javax.script
krl
lpeg
gamequery
mozilla-prism
libs
microsoft-virtualization
sustainable-pace
procedural-music
msdev
windows-live-messenger
rtml

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