Hi,
I have scoured the internet for the last few hours looking for solutions to this and, while I have found a lot of information around this error, I have found nothing that seems to relate to my specific issue. When I run the below code (which I have not written myself, I have pieced it together from other people's code), I get this error:
This is my code:
The code stops at the line:
I have used the UNC of the database I wish to connect to, but the error contains the drive letter designation I gave to the shared drive when I mapped it.
This file will be used by multiple people who all have different drive letter assignations, hence the use of the UNC and that's how the error first occurred, because it was used by someone who has a different drive letter for that same shared drive.
I don't believe it is a user access issue because I absolutely have access to the file (I created it) and the issue still remains if I disconnect that drive and then remap it to another drive letter - the error message remains exactly the same.
Can anybody put me out of my misery, please?
Thank you very much in advance!
Rich
I have scoured the internet for the last few hours looking for solutions to this and, while I have found a lot of information around this error, I have found nothing that seems to relate to my specific issue. When I run the below code (which I have not written myself, I have pieced it together from other people's code), I get this error:
Run-time Error '-2147467259 (80004005)':
P:/Purchasing\Category Spend Report\Category Spend Report\Live_Cat_Spend_For_Queries.xlsx'
is not a valid path. Make sure that the path name is spelled correctly and that you are
connected to the server on which the file resides.
This is my code:
Code:
Option Explicit
Sub Refresh_Industry_Groups()
Dim con As Object
Dim rs As Object
Dim AccessFile As String
Dim strTable As String
Dim SQL As String
Dim i As Integer
Dim sht As Worksheet
Application.ScreenUpdating = False
AccessFile = "\\sdxukst001s\Data\Purchasing\Category Spend Report\Category Spend Report\" _
[indent][/indent]& "Deployment.accdb"
strTable = "qry_Industry_Groups"
Set sht = Worksheets("Industry Groups")
On Error Resume Next
Set con = CreateObject("ADODB.connection")
If Err.Number <> 0 Then
MsgBox "Connection was not created!", vbCritical, "Connection Error"
Exit Sub
End If
On Error GoTo 0
con.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & AccessFile
SQL = "SELECT " _
& " [Ind_Group]," _
& " [Industry Group]," _
& " [Industry Group Description]" _
& " FROM " & strTable _
& " ORDER BY [Industry Group]" _
On Error Resume Next
Set rs = CreateObject("ADODB.Recordset")
If Err.Number <> 0 Then
Set rs = Nothing
Set con = Nothing
MsgBox "Recordset was not created!", vbCritical, "Recordset Error"
Exit Sub
End If
On Error GoTo 0
rs.CursorLocation = 3
rs.CursorType = 1
rs.Open SQL, con
If rs.EOF And rs.BOF Then
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
Application.ScreenUpdating = True
MsgBox "There are no records in the recordset!", vbCritical, "No Records"
Exit Sub
End If
sht.Range("A5:IV1048576").ClearContents
For i = 0 To rs.Fields.Count - 1
sht.Cells(4, i + 1) = rs.Fields(i).Name
Next i
sht.Range("A5").CopyFromRecordset rs
rs.Close
con.Close
Set rs = Nothing
Set con = Nothing
sht.Columns("A:IV").AutoFit
Application.ScreenUpdating = True
End Sub
The code stops at the line:
rs.Open SQL, con
I have used the UNC of the database I wish to connect to, but the error contains the drive letter designation I gave to the shared drive when I mapped it.
This file will be used by multiple people who all have different drive letter assignations, hence the use of the UNC and that's how the error first occurred, because it was used by someone who has a different drive letter for that same shared drive.
I don't believe it is a user access issue because I absolutely have access to the file (I created it) and the issue still remains if I disconnect that drive and then remap it to another drive letter - the error message remains exactly the same.
Can anybody put me out of my misery, please?
Thank you very much in advance!
Rich