
Originally Posted by
TheShabz
store the contents of the cell as a variable. refer to the variable.
You are absolutely correct, but it took me a while to sort it out. Sadly I am not much of a coder, I am better at googling...
Original code I was working with:
Code:
Dim cn As ADODB.Connection, rs As ADODB.Recordset, R As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=PathToMyDatabase;"
Here is what I've done to solve this issue:
Code:
Dim cn As ADODB.Connection, rs As ADODB.Recordset, R As Long, dbPath As String
dbPath = "Data Source=" & Range("A10")
In a snippet above you will see a new variable dbPath I added. The path alone is contained in a cell A10 of my spreadsheet, however cn.Open statement calls for a phrase "Data Source=" to be present in front of the path, and that is why I made it a part of my dbPath variable.
Code:
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
dbPath & ";"
Here I am just calling my variable and closing the statement. And that is it!!!
You guys are probably smirking right now thinking what's the big deal, but I tell you to me it was an accomplishment, and I did pat myself on the shoulder
.