So my problem is that between 2 different computers my connection to the string no longer can open a connection.
Here is what I have:
Dim sFileName As String
Dim sFilePath As String
sFileName = "DataSource.xls"
sFilePath = "C:\test\testingData\"
Dim sConn As String
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sFilePath & sFileName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes"";"
Dim errorObject As ADODB.Error
Set errorObject = CreateObject("ADODB.Error")
On Error GoTo ErrorDisplay:
Dim conn As ADODB.Connection
Set conn = New ADODB.Connection
conn.Open sConn
Dim rst As ADODB.Recordset '* Record Set
Set rst = New ADODB.Recordset
rst.Open sSql, conn, adOpenForwardOnly
Worksheets(1).Range("A2").CopyFromRecordset rst
sSQL = "SELECT * FROM [MySheet$] WHERE [Status] = 2 AND [DocNo] LIKE '%-A%'
When I run this section of code on one computer it runs perfectly as I built it. When I try it on a similar computer it keeps giveing an error "Object variable or With Block variable not set". I have found out that the problem is with the conn.Open sConn but not sure what is causing it.
I have been searching about looking for a solution but as of yet I have not found anything that worked.
Additional Info:
Both computers:
Windows 7 x64
Excel 2007 x32
Any thoughts as to why this would not work?
--Update: I just finished trying the excel file with the macro out on a 3rd windows 7 computer and that one works fine.
--Update:
I have just tried running the program from
sFilePath = "C:\Users\FirstName.LastName\Desktop\"
and
sFilePath = "C:\Users\FirstName.LastName\Desktop\Test\"
The thing I would really like to know is that it's working from the "C:\Users\FirstName.LastName\Desktop\Test\" but none of the others???