ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Connecting to Access using macro (https://www.excelbanter.com/excel-programming/293792-re-connecting-access-using-macro.html)

onedaywhen

Connecting to Access using macro
 
Your code merely creates a connection to a database, it doesn't open any tables.

Replace your line:

' open a recordset

With these lines:

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
With rs
.Source = "SELECT * FROM " & ans
.ActiveConnection = cn
.Open
End With
' Do something with recordset
rs.Close
cn.Close

--

"George" wrote in message ...
Hi there, I am using this code to connect to the access
database but its not opening the tables I want to open:
Sub Auto_Open()
Dim cn As ADODB.Connection
ans = InputBox("What Table you want to analyze?")
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\FolderName\DataBaseName.mdb;"
' open a recordset
End Sub
Pls if you have any information that I can use to fix this
problem let me know



All times are GMT +1. The time now is 10:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com