Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Location
    United Kingdom
    Posts
    3

    Question Unanswered: 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







  2. #2
    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •