Access VBA, delete some characters inside a String (1 Viewer)

AccOUCH

Registered User.
Local time
Today, 05:42
Joined
Sep 27, 2018
Messages
25
I have several records that include some text between square brackets -->

Code:
aaaaaa[aaaaa].
I need to erase that extra content, square brackets included. The String in the example would turn out to be:

Code:
aaaaaa
I'm trying this code:

Code:
Dim sqr as Integer
Dim origin as String
Dim result as String

InStr(origin,[)
So I can find the first square bracket, but I does not do the job.

Any idea?
 
Last edited:

plog

Banishment Pending
Local time
Today, 07:42
Joined
May 11, 2011
Messages
11,611
The arguments of InStr are strings (https://www.techonthenet.com/oracle/functions/instr.php). You have declared the variable origin as a string--however nothing is inside it. origin is null and thus nothing will ever be found inside of it to match. Next you have used the symbol [, which Access has no clue about. Its not a variable and you haven't surrounded it by quotes (which is how you make strings), so it has no idea what you meant to do with it.
 

Minty

AWF VIP
Local time
Today, 12:42
Joined
Jul 26, 2013
Messages
10,354
If you simply want to discard the entire string to the right of the first [ character you are on the correct path.

Origin = "Your test[String]"

Msgbox Left([Origin], InStr([Origin], " [") - 1)
 

AccOUCH

Registered User.
Local time
Today, 05:42
Joined
Sep 27, 2018
Messages
25
Thanks! It has been a pair of good solutions!
 

Users who are viewing this thread

Top Bottom