string function ( right function ) (1 Viewer)

murray83

Games Collector
Local time
Today, 23:52
Joined
Mar 31, 2017
Messages
729
this is what i have found by searching the great wide web

Code:
Right([SerialNumber],3)

If [SerialNumber] is “CD234”, the result is “234”.

ok that is fine but i dont/cant put that in the control source and would like a VBA way of doing it on update or click of command button

this is my data

062963340006 003 B003SEP2191558BA0423 2 (300)

and the bit i need to trim is the "2 (300)"

all i need to keep is the data with in the brackets

help appreciated :D
 

Ranman256

Well-known member
Local time
Today, 18:52
Joined
Apr 9, 2015
Messages
4,337
you want the left 3 of the right4:

=left(Right(field,4),3)

(if its always a 3 digit string in the parens)
 

Minty

AWF VIP
Local time
Today, 23:52
Joined
Jul 26, 2013
Messages
10,371
Is the (300) always in the exactly the same place - same number of characters into the string ?
 

static

Registered User.
Local time
Today, 23:52
Joined
Nov 2, 2015
Messages
823
If it's the only value in brackets

value = Split(Replace("062963340006 003 B003SEP2191558BA0423 2 (300)", ")", "("), "(")(1)
 

murray83

Games Collector
Local time
Today, 23:52
Joined
Mar 31, 2017
Messages
729
you want the left 3 of the right4:

=left(Right(field,4),3)

(if its always a 3 digit string in the parens)

Is the (300) always in the exactly the same place - same number of characters into the string ?

In answer to both questions no its not always 300 it's between 1 and N but yes always same place

if this helps this is a screen shot of the place im pasting it into
 

Attachments

  • just here.png
    just here.png
    36.7 KB · Views: 63

murray83

Games Collector
Local time
Today, 23:52
Joined
Mar 31, 2017
Messages
729
could i put something like this in the on current or on load for the form

Code:
Me.Total.Value = Right([Total], 2)

???
 

static

Registered User.
Local time
Today, 23:52
Joined
Nov 2, 2015
Messages
823
Where does the value come from?
Do you need to keep the original value or just the trimmed result?

If you store and need to keep the whole string you can just use a calculated value in a field or control.
=right(total,7)
 

murray83

Games Collector
Local time
Today, 23:52
Joined
Mar 31, 2017
Messages
729
no need to keep original just the trimmed

so would i put that in the control source ?

or on button click event
 

static

Registered User.
Local time
Today, 23:52
Joined
Nov 2, 2015
Messages
823
If you keep the original value...

You would put that in the control source of a textbox

or a field in query

TrimmedValue: right(total,7)

which is the source for a control.

You didn't answer the first question.

If you paste the value into a control you would strip out the unneeded part in an event e.g. the controls beforeupdate event so only the part you need is stored in the table.
 

murray83

Games Collector
Local time
Today, 23:52
Joined
Mar 31, 2017
Messages
729
query would this work
 

Attachments

  • here..png
    here..png
    6.9 KB · Views: 67

static

Registered User.
Local time
Today, 23:52
Joined
Nov 2, 2015
Messages
823
You have put the string function in the criteria row.
Criteria is used for filtering.

Instead of Total you need to type what I wrote above.

TrimmedValue: right([total],7)

Where TrimmedValue is the name you want to give the calculated field.

Right gets the right of the string you pass in, in this case the field total.

'2 (300)' is 7 characters, not 3.
 

murray83

Games Collector
Local time
Today, 23:52
Joined
Mar 31, 2017
Messages
729
You have put the string function in the criteria row.
Criteria is used for filtering.

Instead of Total you need to type what I wrote above.

TrimmedValue: right([total],7)

Where TrimmedValue is the name you want to give the calculated field.

Right gets the right of the string you pass in, in this case the field total.

'2 (300)' is 7 characters, not 3.

ok i pasted
Code:
TrimmedValue: right([total],7)
into criteria and had the following error
 

Attachments

  • error.png
    error.png
    14.7 KB · Views: 62

static

Registered User.
Local time
Today, 23:52
Joined
Nov 2, 2015
Messages
823
edit reading fail

you need to remove the criteria and paste into the field row
 

murray83

Games Collector
Local time
Today, 23:52
Joined
Mar 31, 2017
Messages
729
here is the database so you can see
 

Attachments

  • de-allocate.accdb
    916 KB · Views: 62

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:52
Joined
May 7, 2009
Messages
19,242
Use:

Mid([Total],Instrrev([Total], "(")+1,Instrrev([Total], ") ")-Instrrev([Total], "(")-1)
 

static

Registered User.
Local time
Today, 23:52
Joined
Nov 2, 2015
Messages
823
You added the new field.
You just need to change the controlsource for the Total textbox in the subform to the new field.

View attachment de-allocate.accdb

The data in your table didn't match the format you said it should be.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:52
Joined
May 7, 2009
Messages
19,242
Yes you are correct. Can parse any length.
 

Users who are viewing this thread

Top Bottom