Connecting Excel to Access DB Gives "Not a valid file name" Error

mp1115

New Member
Joined
Dec 23, 2015
Messages
13
Hello All,

When trying to open a connection from a worksheet to an Access database I get the following error:

Run-time error '-2147467259(80004005)': Not a valid file name.


Here is the first part of the code where the error takes place:

Code:
Public Const Conn As String = "Data Source=\Drive:\Folder\name.accdb;"

Private Sub Export_Click()
    Dim rs As New ADODB.Recordset
    Dim cn As New ADODB.connection
    Dim tbl As String

    tbl = "Table"

    [COLOR=#ff0000]cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & Conn[/COLOR]
    rs.Open tbl, cn, adOpenKeyset, adLockOptimistic, adCmdTableDirect

The debugger points me to the red line.

Forum member CalcSux78 gave me the code (in this thread -> http://www.mrexcel.com/forum/excel-questions/910496-macro-export-individual-cells-table-access.html) and it worked perfectly in my private user drive but once I moved the file to a network drive I started getting errors. Initially I got "Authentication failed." because I accidentally deleted "Data Source=" from before the path\filename (oops) but after correcting that I now get the file name error.

I can promise that the file name is spelled correctly and I am connected to the network; has anyone encountered something like this before?

I appreciate all ideas and input!

Thanks.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Please forgive me for wasting time and forum space; the error was simply because of the initial backslash I had before the file path.

Thanks to anyone who may have been looking into helping me!
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

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