If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > VBA ~ Searching & Replaccing text in a field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-05-04, 10:32
bigmantone bigmantone is offline
Registered User
 
Join Date: Jun 2004
Location: United Kingdom
Posts: 3
Question VBA ~ Searching & Replaccing text in a field

Hi All,

Please can you help.

I am trying to create VBA code that can search each record in a particular field of a recordset and replace it?

The entrys look like this

12456.gif
13456.gif
12789.gif
78945.jpg
79654.jpp

What I want to do is find .gif and replace it to .jpg

Hers my code so far, as you can see I can get into the recordset.

Any help would be great

Function update()

Dim db As Database
Dim rec As Recordset

Set db = CurrentDb
Set rec = db.OpenRecordset("Table1")

Do While Not rec.EOF
rec.Edit
rec("Sale") = [Text21].Value
rec("Catapic") = [Text23].Value
If rec("Photo name") = "Noimage" Then rec("Photo name") = "Noimage.jpg"
If rec("Photo thumb_name") = "Noimage" Then rec("Photo thumb_name") = "Noimage.jpg"
If rec("Photo name") = ".GIF" Then rec("Photo name") = ".jpg" ' this is where I am stuck

rec.update
rec.MoveNext

Loop

update = True


End Functio






Reply With Quote
  #2 (permalink)  
Old 06-05-04, 22:16
CyberLynx CyberLynx is offline
Stuck on my opinions...
 
Join Date: Nov 2003
Posts: 1,487
This routine will change the Photo Name "MyPicture.GIF" to "MyPicture.jpg"

Code:
If Instr(rec.[Photo name], ".GIF") = True Then 
   rec.[Photo name] = Left(rec.[Photo name], Instr(rec.[Photo name], ".GIF") - 1) & ".jpg" 
End If
OR cleaner yet....

Code:
Dim Strg As String
Strg = rec.[Photo name]
If Instr(Strg, ".GIF") = True Then 
   rec.[Photo name] = Left(strg, Instr(Strg, ".GIF") - 1) & ".jpg" 
End If

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On