Solved

ADO Connection from Excel?

Posted on 2011-03-23
6
422 Views
Last Modified: 2012-05-11
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
<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>

Open in new window

0
Comment
Question by:Washcare
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:drilus
ID: 35199130
Yes. The key will be the connection string.

For Excel:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source='Book1.xls';Extended Properties=Excel 8.0;HDR=YES;

Excel also uses the first row as headers for Columns.
0
 

Author Comment

by:Washcare
ID: 35199187
drilus

Would I use this within Excel to create a new connection or do I use  it within an .asp page?
0
 
LVL 5

Expert Comment

by:drilus
ID: 35199254
within an .asp page.

Try this example from Microsoft:
http://support.microsoft.com/kb/195951
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Washcare
ID: 35199291
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?

0
 
LVL 5

Accepted Solution

by:
drilus earned 500 total points
ID: 35199592
Well, this is the best I can do. http://www.thescarms.com/dotnet/AspExport.aspx

I know it's possible but I don't know the asp syntax well enough to help you further.
0
 

Author Closing Comment

by:Washcare
ID: 35365372
Many thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add a loading gif while php runs server side 15 63
certificate error on website only in internal network 24 63
window close link 7 32
Session on Html 8 37
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question