Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace function in Access97 or just in Access2000? 1

Status
Not open for further replies.

jane30

Programmer
Nov 14, 2000
92
0
0
US
Hi, Is there Replace function in Access97? Why I don't see it in the Help topics? I have Microsoft DAO 3.5 Object Library reference. Do it matter?
 
It's not a DAO thing, but rather a VBA library function. It's there--look in VBA Help > Contents > Language Reference > Functions.

*This may be one of a number of functions that breaks between MDAC versions.
 
There isn't as such but you can write your own. I haven't tested this but something like this might work:

Code:
Public Function Replace(old_text As String, start_num As Long, num_chars As Long, new_text As String) As String
On Error GoTo Err_Replace
    If start_num <= Len(old_text) Then
        If start_num + num_char <= Len(old_text) Then
            Replace = Left$(old_text, start_num - 1) & new_text & Mid$(old_text, start_num + num_chars)
        Else
            MsgBox &quot;Your number of characters conflicts with the length of your original text&quot;, vbExclamation
        End If
    Else
        MsgBox &quot;Your start position conflicts with the length of your original text&quot;, vbExclamation
    End If

Exit_Replace:
    Exit Function
Err_Replace:
    MsgBox Err.Number & &quot;: &quot; & Err.Description, vbExclamation
    Resume Err_Replace
End Function
[pc2]
 
FROM 2K Help:

Replace Function


Description

Returns a string in which a specified substring has been replaced with another substring a specified number of times.

Syntax

Replace(expression, find, replace[, start[, count[, compare]]])

The Replace function syntax has these named arguments:

Part Description
expression Required. String expression containing substring to replace.
find Required. Substring being searched for.
replace Required. Replacement substring.
start Optional. Position within expression where substring search is to begin. If omitted, 1 is assumed.
count Optional. Number of substring substitutions to perform. If omitted, the default value is –1, which means make all possible substitutions.
compare Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. See Settings section for values.



Settings

The compare argument can have the following values:

Constant Value Description
vbUseCompareOption –1 Performs a comparison using the setting of the Option Compare statement.
vbBinaryCompare 0 Performs a binary comparison.
vbTextCompare 1 Performs a textual comparison.
vbDatabaseCompare 2 Microsoft Access only. Performs a comparison based on information in your database.
 
Office '97 VBA has a VB 5 base which does not have the Replace, Split and Join functions among other features. Office 2000 has a VB6 base which has the functions. Do a search, there are examples of a Replace function written in VB5. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top