View Full Version : ASP Data Grabber
npala2001
09-22-2004, 05:41 PM
Does anyone know where I can get some script that will grab fields from a Access Database and CDONTS them. The field that this script would need to grab is a email address so that will probably make things a lot easier to create. Or does someone know the name of this process so that I can search in google.
Thanks
NEExt
09-22-2004, 06:21 PM
The following code generates email. There are tons of websites on how to connect to an Access database to retrieve the email addresses. I found this one helpful when I first started. http://www.webwizguide.info/asp/tutorials/connecting_to_a_database.asp
<% Option Explicit
Dim strSubject, objEmail
strSubject = "This is the body of the message"
strSubject = strSubject & "<br>More Body"
Set objEmail = CreateObject("CDONTS.NewMail")
objEmail.From = whomever
objEmail.To = yourRecordSet("nameofemailfield")
objEmail.CC = yourRecordSet("nameofemailfield")
objEmail.BCC = ""
objEmail.Importance = "2" 'sets exclamation importance
objEmail.Subject = "blah"
objEmail.BodyFormat = "0" 'I think this and the next line designate an HTML message
objEmail.MailFormat = "0"
objEmail.Body = strSubject
objEmail.Send
Set objEmail = Nothing
Response.Redirect("emailsuccess.htm")
%>
npala2001
09-22-2004, 08:41 PM
What can I do if I want to call a query (That has been pre-established) from within the database, but not an actual table?
NEExt
09-22-2004, 10:28 PM
Set adoCon = Server.CreateObject("ADODB.connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("mydatabase.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
strSQL = "name_of_your_access_query"
rs.Open strSQL, adoCon
If you need to pass a variable to your query then you need to put the SQL on the ASP page.
npala2001
09-23-2004, 11:06 PM
I want this code to be separate from the ASP code I already have. I want the code to run on a particular date (To allow all of the facilities to submit their report) – Is that right or not?
Is the coding right so far?
<% Option Explicit
Dim strSubject, objMsg
strSubject = "This is the body of the message"
strSubject = strSubject & "<br>More Body"
strFrom = "My Email Address"
Set adoCon = Server.CreateObject("ADODB.connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("rcqr.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
strSQL = "NOENTRY_Quarter_1_2004"
rs.Open strSQL, adoCon
Set objMsg = Server.CreateObject("CDONTS.NewMail")
objMsg.From = strFrom
objMsg.To = "facility_contact"
objMsg.CC = strFrom
objMsg.Subject = strSubject
objMsg.BodyFormat = "0" 'I think this and the next line designate an HTML message
objMsg.MailFormat = "0"
objMsg.Body = strBodies
objMsg.Importance = "2" 'sets exclamation importance
objMsg.Send
Set objMsg = Nothing
Response.Redirect("http://bpcaccess/hse/")
%>
npala2001
09-24-2004, 05:58 PM
Anyone have any comments or suggestions
NEExt
09-24-2004, 06:14 PM
I don't know what kind of advice or information you are looking for exactly, and you didn't give any information on what you are actually trying to do in your post:
Assuming that objMsg.To = "facility_contact" is the name of the field in the DB where you store email addresses then you need to reference it as rs("facility_contact"). Also, I don't know what kind of recordset your Query returns, but this will only send email to the first record on the list.
Don't forget to close your rs and DB connection.
rs.Close
Set rs = Nothing
Set adoCon = Nothing
npala2001
09-24-2004, 07:13 PM
Is their a way to loop the code to where it will grab each record within the query "The field that contains the email address". Sorry for not getting into the details.
npala2001
09-26-2004, 10:34 AM
Anyone else have any ideas on a way to send to multiple field entries?
npala2001
09-27-2004, 05:43 PM
This is what I have so far. Also what would be a good method on testing this code.
<% Option Explicit
Dim strSubject, objMsg
strSubject = "You have not yet submitted a Report into the Responsible Care Database"
strSubject = strSubject & "<br>Please click on the link to submit a <a href="http://bpcaccess/hse/RespDatabase_interface/Table/submission_form.asp">Responsible Care Quarterly Report</a>"
strFrom = email address
Set adoCon = Server.CreateObject("ADODB.connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("testrcqr.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")
strSQL = "NOENTRY_Quarter_1_2004"
rs.Open strSQL, adoCon
Set objMsg = Server.CreateObject("CDONTS.NewMail")
objMsg.From = strFrom
objMsg.To = "facility_contact"
objMsg.CC = strFrom
objMsg.Subject = strSubject
objMsg.BodyFormat = "0" 'I think this and the next line designate an HTML message
objMsg.MailFormat = "0"
objMsg.Body = strBodies
objMsg.Importance = "2" 'sets exclamation importance
objMsg.Send
Set objMsg = Nothing
rs.Close
Set rs = Nothing
Set adoCon = Nothing
Response.Redirect("http://www.www.www")
%>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.