help with replace function

×

מ×יר

hi

i would like to replace substrings in txt files in folder and its subfolders

i have the sring to find and the string to replace in access table

it is my first time to do anything with vba

the function i found is here


Function Replace(ByVal Valuein As String, ByVal WhatToReplace As _
String, ByVal Replacevalue As String) As String
Dim Temp As String, P As Long
Temp = Valuein
P = InStr(Temp, WhatToReplace)
Do While P > 0
Temp = Left(Temp, P - 1) & Replacevalue & _
Mid(Temp, P + Len(WhatToReplace))
P = InStr(P + Len(Replacevalue), Temp, WhatToReplace, 1)
Loop
Replace = Temp
End Function

can someone help me with that?

thank you
 
J

John W. Vinson

hi

i would like to replace substrings in txt files in folder and its subfolders

i have the sring to find and the string to replace in access table

it is my first time to do anything with vba

the function i found is here


Function Replace(ByVal Valuein As String, ByVal WhatToReplace As _
String, ByVal Replacevalue As String) As String
Dim Temp As String, P As Long
Temp = Valuein
P = InStr(Temp, WhatToReplace)
Do While P > 0
Temp = Left(Temp, P - 1) & Replacevalue & _
Mid(Temp, P + Len(WhatToReplace))
P = InStr(P + Len(Replacevalue), Temp, WhatToReplace, 1)
Loop
Replace = Temp
End Function

can someone help me with that?

thank you

What version of Access are you using? There is now a builtin Replace()
function; this looks like a function which was written for Access97 or
earlier, which didn't have the function built in.

If you could describe what you're trying to accomplish (replace what, with
what, in which records???) we may be able to give you more specific help.

John W. Vinson [MVP]
 
×

מ×יר

thank you for reply

i use access 2003

i would like to replace substrings that located in other folders and sub
folders on my pc such as names and adresses.

since they located in few files and there are many records in each file i
want to do it with macro from the db

in the db i have a table with 2 columns that contains the substring to find
and the substring to replace.

i hope i am clear now

thanks again
 
J

John W. Vinson

thank you for reply

i use access 2003

i would like to replace substrings that located in other folders and sub
folders on my pc such as names and adresses.

since they located in few files and there are many records in each file i
want to do it with macro from the db

in the db i have a table with 2 columns that contains the substring to find
and the substring to replace.

i hope i am clear now


Well... I want to be sure I understand.

Are you replacing strings in Windows filenames, e.g. renaming "G:/Test
Data/wibble.mdb" to "G:/Test Data/wobble.mdb"?

Or are you changing the values of text within files in folders on your disk?

The latter may be difficult, since Access cannot natively open an arbitrary
file and edit it. It could also be quite dangerous since you could damage
files on your disk.

John W. Vinson [MVP]
 
×

מ×יר

i want to change text within the file not the file names

this why i thought using vba for

any idea?

by the way i found the built in function for replace within the table

what i need is that it can work on text files outside of the db in folders
and subfolders

thnk you again
 
J

John W. Vinson

i want to change text within the file not the file names

this why i thought using vba for

any idea?

by the way i found the built in function for replace within the table

what i need is that it can work on text files outside of the db in folders
and subfolders

If Access can do this at all, I don't know how.

Access is designed to manipulate data within Access tables, or within linked
tables. It wasn't written to let you open any arbitrary file, of any arbitrary
file type, on your computer and change data within that file!

What *ARE* these files? Are they serving the role of database tables? If so,
why not store them in database tables, and export them to files if needed for
some other application?

John W. Vinson [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top