Solved

ADO Connection from Excel?

Posted on 2011-03-23
6
414 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
Comment Utility
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
Comment Utility
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
Comment Utility
within an .asp page.

Try this example from Microsoft:
http://support.microsoft.com/kb/195951
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Washcare
Comment Utility
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
Comment Utility
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
Comment Utility
Many thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to count occurrences of each item in an array.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now