VBA

Moderators: PavlinII
Number of threads: 1599
Number of posts: 2976

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
substring function in VBA? Posted by blueknight on 22 Jan 2002 at 8:50 PM
I'm new to vba - using it with access. I'm building sql statements on the fly. Sometimes the dynamic text has a ' (quote) in it (O'Toole). How do I escape that out in vba. I looked for a substring command, didn't find it. I'm using access 2000 and its vb.

Report
Re: substring function in VBA? Posted by Moz on 3 Feb 2002 at 5:08 AM
: I'm new to vba - using it with access. I'm building sql statements on the fly. Sometimes the dynamic text has a ' (quote) in it (O'Toole). How do I escape that out in vba. I looked for a substring command, didn't find it. I'm using access 2000 and its vb.
:
:
Try looking up the help on the Instr, len, right and/or left commands in VBA. Not sure exactly what you're trying to do, but if you're looking for a substring function, you will find the answer in the these. InStr looks for a matching string or character; Len defines the length of a string; and left and right get a substring based on a start position (which can be found from instr).

Hope this helps,
Moz.
Report
Re: substring function in VBA? Posted by Ara_cam on 12 Feb 2002 at 7:37 AM
: : I'm new to vba - using it with access. I'm building sql statements on the fly. Sometimes the dynamic text has a ' (quote) in it (O'Toole). How do I escape that out in vba. I looked for a substring command, didn't find it. I'm using access 2000 and its vb.
: :
: :
: Try looking up the help on the Instr, len, right and/or left commands in VBA. Not sure exactly what you're trying to do, but if you're looking for a substring function, you will find the answer in the these. InStr looks for a matching string or character; Len defines the length of a string; and left and right get a substring based on a start position (which can be found from instr).
:
: Hope this helps,
: Moz.
dim x as string
dim y as string
dim n as integer
y="O'Toole"
x="'"
n = InStr (1, y, x, vbTextCompare

This will tell you if the the value in X is in the string Y, and what position it is first found at.

y = Replace(y, x, ,":")
This will replace all occurances of X within Y with : (or whatever is in the third variable). Other options exist for the Replace command, so check the help file.

Hope this helps!




Report
Re: substring function in VBA? Posted by SilentRage on 12 Feb 2002 at 10:15 PM
yeah, rather than replacing the ' with ":" you may replace it with nothing. I use replace often to strip characters.

Variable = Replace("O'Tool", "'", "")



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.