Update hyperlink path

jumbledore

Active Member
Joined
Jan 17, 2014
Messages
262
I had created an access database to store path names of files on my local drive using the below vba code:

Dim rst As dao.Recordset

Set rst = MyDB.OpenRecordset("MyTable", dbOpenDynaset, dbAppendOnly)

With rst
. AddNew
! [File_path] ="Link" & "#c:\myfiles#"
.Update

rst.Close


I have only mentioned the code relevant to my question and have left out the other details. The code works fine and I have updated more than 2000 records using it but now I want to change the path of the hyperlink from "#c:\myfiles#" to "#c:\thosefiles#"
How do I do so?

Thanks
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
It can be done in an update query:

Code:
UPDATE MyTable SET File_Path = Replace([File_Path],"c:\myfiles","c:\thosefiles");

Or in VBA (Untested)
Code:
Sub UpdateFilePath()
Dim rs1 As Recordset
 Set rs1 = CurrentDb.OpenRecordset("MyTable")
    With rs1
        Do Until .EOF = True
        .Edit
        !File_Path = Replace(!File_Path, "c:\myfiles", "c:\thosefiles")
        .Update
        .MoveNext
        Loop
     End With
Set rs1 = Nothing
End Sub
 
Upvote 0
It can be done in an update query:

Code:
UPDATE MyTable SET File_Path = Replace([File_Path],"c:\myfiles","c:\thosefiles");

Or in VBA (Untested)
Code:
Sub UpdateFilePath()
Dim rs1 As Recordset
 Set rs1 = CurrentDb.OpenRecordset("MyTable")
    With rs1
        Do Until .EOF = True
        .Edit
        !File_Path = Replace(!File_Path, "c:\myfiles", "c:\thosefiles")
        .Update
        .MoveNext
        Loop
     End With
Set rs1 = Nothing
End Sub

Sorry but your solution doesn't work. I tried running the SQL query for 1 record. It gave me a message saying that it was updating a record but when I checked, the link still points to the previous path name.
 
Upvote 0
Code:
Sorry but your solution doesn't work. I tried running the SQL query for 1 record. It gave me a message saying that it was updating a record but when I checked, the link still points to the previous path name.

Works in Access 2016 (just tested) and has previously worked for me in previous versions.

How are you limiting to one record, are you sure the record you are limiting it to includes the string being replaced?
 
Upvote 0
Code:

Works in Access 2016 (just tested) and has previously worked for me in previous versions.

How are you limiting to one record, are you sure the record you are limiting it to includes the string being replaced?

I am using version 2007 but just to let you know that the field "File_path" displays the hyperlink as"Link" and not the actual path name.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top