Washcare
asked on
ADO Connection from Excel?
Good Afternoon
Is it possible to create an ADO Connection from Excel to an Access database? The attached code (a .asp) alows me to display the last record of the database on a web page, so is it possible to use the same logic as a connection within Excel?
Thanks
Is it possible to create an ADO Connection from Excel to an Access database? The attached code (a .asp) alows me to display the last record of the database on a web page, so is it possible to use the same logic as a connection within Excel?
Thanks
<html>
<head>
<title>Database</title>
</head>
<body bgcolor="white" text="black">
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsdatabase 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Comments.mdb")
'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=database"
'Create an ADO recordset object
Set rsdatabase = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT TOP 1 tblComments.S1, tblComments.S2, tblComments.S3, tblComments.Date, tblComments.EN, tblComments.CW, tblComments.Status, tblComments.SSO FROM tblComments ORDER BY ID_no DESC;"
'Open the recordset with the SQL query
rsdatabase.Open strSQL, adoCon
'Loop through the recordset
Do While not rsdatabase.EOF
'Write the HTML to display the current record in the recordset
Response.Write ("<br>")
Response.Write (rsdatabase("S1"))
Response.Write ("<br>")
Response.Write (rsdatabase("S2"))
Response.Write ("<br>")
Response.Write (rsdatabase("S3"))
Response.Write ("<br>")
Response.Write (rsdatabase("Date"))
Response.Write ("<br>")
Response.Write (rsdatabase("EN"))
Response.Write ("<br>")
Response.Write (rsdatabase("CW"))
Response.Write ("<br>")
Response.Write (rsdatabase("Status"))
Response.Write ("<br>")
Response.Write (rsdatabase("SSO"))
Response.Write ("<br>")
'Move to the next record in the recordset
rsdatabase.MoveNext
Loop
'Reset server objects
rsdatabase.Close
Set rsdatabase = Nothing
Set adoCon = Nothing
%>
</body>
</html>
ASKER
drilus
Would I use this within Excel to create a new connection or do I use it within an .asp page?
Would I use this within Excel to create a new connection or do I use it within an .asp page?
ASKER
drilus
The example looks at updating the .asp page from Excel, I would like Excel to be updated from the data within the .asp page?
The example looks at updating the .asp page from Excel, I would like Excel to be updated from the data within the .asp page?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks
For Excel:
Provider=Microsoft.Jet.OLE
Excel also uses the first row as headers for Columns.