Equivalent Formula For Trimming Data

molsen

Registered User.
Local time
Today, 13:03
Joined
Sep 13, 2012
Messages
50
Hi All

I am using the following formula to strip out certain characters from a field using MS Excel, containing similar to the following data:

Miss M A Budgett W/T *094169/2

In the next field to the right, I want everying after the * to appear:

=TRIM(REPLACE(D15,1,FIND("*",D15)," "))

Does anyone know what the equivalent code would be so that I can replicate this action in an Access 2010 query?

Many thanks
 
Here's a list of common Access functions: http://www.techonthenet.com/access/functions/

Trim is still good
For Replace you would use Mid(http://www.techonthenet.com/access/functions/string/mid.php)
For Find you would use InStr (http://www.techonthenet.com/access/functions/string/instr.php)

Give it a shot, check out the link I provided and post back here any issues you have.

Thanks Plog, appreciate your help. I am struggling with the syntax. Would you be kind enough to give me the equivalent code to find everything after the * in the text below? It would be better if I could actually cut that reference from the original field and place it in a new one in the query:

Miss M A Budgett W/T *094169/2

I've had a go at it, but keep getting an error message!
 
=Mid([YourText], InStr(1, [YourText], "*")+1, Len([YourText]))
 
If it's everything after the "*" then I suppose the Len() part can be dropped:
Code:
=Mid([YourText], InStr(1, [YourText], "*")+1)
 
If it's everything after the "*" then I suppose the Len() part can be dropped:

Oh, yes. That's my habit of using Excel a lot, where the parameter is not optional.
 
Last edited:
If it's everything after the "*" then I suppose the Len() part can be dropped:
Code:
=Mid([YourText], InStr(1, [YourText], "*")+1)

Thank you! Works a treat...

And if I only want it to show the characters after the *, and to ignore any characters preceeding it?
 

Sorry vba, I'm being a numpty plonker. What I really meant was that if there are any fields which dont contain a * at all, then it shouldnt copy anything across :confused:.

There are a lot of fields where just the name is displayed, I am only looking to copy anything with a reference after the *, otherwise it should be left blank.
 
Another option is the split function.

Split([Yourtext],"*")(0) gives all before the *
Split([Yourtext],"*")(1) gives all behind the *
 
Sorry vba, I'm being a numpty plonker. What I really meant was that if there are any fields which dont contain a * at all, then it shouldnt copy anything across :confused:.

There are a lot of fields where just the name is displayed, I am only looking to copy anything with a reference after the *, otherwise it should be left blank.


Something like:
Code:
IIf(Instr(1, [YourText], "*"), Mid([YourText], InStr(1, [YourText], "*")+1),"")
 
Mile-O is on it.

I think it would be better for the empty string "" to be Null.
 
My deep and unconditional respect to you all for your help! :D
 
Another option is the split function.

Split([Yourtext],"*")(0) gives all before the *
Split([Yourtext],"*")(1) gives all behind the *

Hi All

When I try to insert this into a field in a query whilst in build,

Payee Name: Split([DE_ppayee],"*")(1)

I get a message telling me "The expression you entered has an invalid
.(dot) or ! operator or invalid parentheses.

Can anyone help?

Tks
 
Would have thought Split() worked purely in VBA. Certainly if I try to replicate it I get the same error as yourself. However, a search of the form highlights othe threads where use of the Split() function in this way has been offered as a solution. Maybe it worked in prior versions.

Anyway, create a module and put this code in:

Code:
Public Function GetPart(ByRef SplitText As String, ByRef Delimiter As String, _
    ByRef SplitPart As Long) As String
    On Error Resume Next
    Dim strText() As String
    strText() = Split(SplitText, Delimiter)
    GetPart = strText(SplitPart)
End Function

In your query:

Code:
Payee Name: GetPart([DE_ppayee],"*",1)
 
Eval() and anything that returns an array doesn't work in queries.

I'm still in favour of Mile-O's original solution.
Something like:
Code:
IIf(Instr(1, [YourText], "*"), Mid([YourText], InStr(1, [YourText], "*")+1),[COLOR="Blue"]Null[/COLOR])
 

Users who are viewing this thread

Back
Top Bottom