Does anyone know of a VB/VBA equivalent statement(s) of COBOL’s INSPECT REPLACING statement?
James
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Equivelant code/command (Access 97)
Try explaining what the COBOL function does for those of us who never succumbed to COBOL. Access 97/VBA 5 did not have a built-in replace function (Access 2000/VBA 6 does have one), but most of us built our own routines to accomplish the same thing. Tell us what you’re trying to do and someone will be able to provide you with some code assistance.
COBOL’s INSPECT REPLACING looks through the given string for a given character or series of characters and replaces them with whatever you specified.
Basically, I want to find all single quotes in a string and make it 2 single quotes.
Anyone know an easy method which also does it extra faast with minimual processor and resource overhead?
James
Here’s a routine I wrote in Access 97 to do what you want. You could make it more efficient by replacing the variants with string variables since those take less memory than variants. I think I used variants in the first place because it allowed me to search for things like chr(10) and other non-printing characters in a string.
Function ReplaceAll(varIn As Variant, _ varFind As Variant, _ varNew As Variant) As Variant 'Created by Charlotte Foust 'Replaces all instances of varFind in the passed varIn Dim intFindLen As Integer Dim intFindPos As Integer Dim varOutput As Variant 'initialize the variables varOutput = varIn intFindLen = Len(varFind & "") intFindPos = 0 If Not IsNull(varIn) Or IsNull(varFind) Then 'If varIn contains input or if a varNew 'will replace the existing contents, 'See if varFind exists in varIn. If IsNull(varFind) Then varOutput = varNew Else intFindPos = InStr(varIn, varFind) If intFindPos > 0 Then 'If varFind exists, replace all instances. Do varOutput = Left(varOutput, intFindPos - 1) _ & varNew _ & Mid(varOutput, intFindPos + intFindLen) intFindPos = InStr(intFindPos + 1, varOutput, varFind) Loop Until intFindPos = 0 End If 'intFindPos > 0 End If 'IsNull(varFind) End If 'Not IsNull(varIn) Or IsNull(varFind) ReplaceAll = varOutput End Function 'ReplaceAll(varIn As Variant, _ varFind As Variant, _ varNew As Variant) As Variant
I had a look at it – it seems to be very efficient and what I am looking for. Problem is that I cannot assume they have Access 2000 or IE5.x.
And being a missions organisation in Asia, we have VBScripting turned off on the email side to help cut down on viruses.
Thanks for the suggestion anyway.
James
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.