Question

I have a function that successfully takes data from multiple excel files in different locations and combines them all into one access table.

Dim rst As New ADODB.Recordset
rst.Open "Files", CurrentProject.Connection
rst.MoveFirst
Do While Not rst.EOF
MsgBox rst.Fields("Filelist")    
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "MechanicalData", rst.Fields("Filelist"), True    


Dim rstmech As New ADODB.Recordset
rstmech.Open "MechanicalData", CurrentProject.Connection
rstmech.MoveFirst
Do While Not rstmech.EOF
    If IsNull(rstmech.Fields("FolderPath")) Then
        rstmech.Fields("FolderPath") = rst.Fields("Filelist")    'Error 3251 here
        rstmech.Update
        End If
        rstmech.MoveNext
Loop
        rstmech.Close
        Set rstmech = Nothing

rst.MoveNext
Loop
rst.Close
Set rst = Nothing

I want to add a field which has the proper hyperlink for each row in the new table, so that the user will be able to navigate back to the excel file. Is there a quick and dirty way to do this? I know I could probably throw a nested loop under the DoCmd.TransferSpreadSheet clause, but I don't know how I would index that.

I've updated my code with a nested while loop, which is supposed to go through each row in the new table and add the appropriate link. I'm getting the error:

Run-Time error '3251':
Current Recordset does not support updating. 
This may be a limitation of the provider, or of the selected locktype. 

Any ideas as to how to fix this?

Alternative, possibly faster method: the outer loop above currently adds data to the bottom, so if the link is added to each record at the end of each iteration, I can have it add the link only to empty entries in that field, essentially doing one batch per hyperlink. Something along the lines of:

UPDATE [MechanicalData] SET [MechanicalData].OpenFile = rst.Fields("Filelist")
WHERE [MechanicalData].OpenFile Is Null

Obviously I can't run that code as is, but I am not sure where to go from there.

Was it helpful?

Solution

I would build an Update query with a parameter which you can feed in & execute on every iteration of the loop in your code. This discussion is probably for an older version than you are using, but I think the points raised could be useful: http://www.utteraccess.com/forum/modify-hyperlink-addre-t1927596.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top