Important alert: (current site time 7/15/2013 11:01:31 PM EDT)
 

VB icon

Easy Access ADO

Email
Submitted on: 12/24/2005 4:45:10 AM
By: Aaron Innes  
Level: Intermediate
User Rating: Unrated
Compatibility: ASP (Active Server Pages), HTML, VbScript (browser/client side)
Views: 9131
(About the author)
 
     To allow easy use of the ADO Data Objects to connect to an access database.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
' for :Easy Access ADO
'**************************************
This class in copyright 2005 Aaron M. Innes
You may use it free without my recognition and you may change the code for your own use and you may distribute the modified version to any person, but you may not claim copyright for the modified version and you must include my name and copyright in the modified version.
You also may not sell the original class nor claim that you wrote it. If you do distribute the original class you can not charge for the distribution.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Easy Access ADO
' Description:To allow easy use of the ADO Data Objects to connect to an access database.
' By: Aaron Innes
'
' Assumes:To use this code use an asp include on the top of the page
EX: <!--#include file="adodb.asp"-->
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=9327&lngWId=4'for details.'**************************************

Copyright © 2005 Aaron M. Innes - All Rights Reserved
<%
class mydb
	'strconn="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="
	'strconn=strconn & server.mappath(accessDB) & ";"
	private strconn
	private objconn
	private objrs
	private blopen
	private bleof
	private blbof
	private bladding
	private sub Class_Initialize()
		blopen = 0
		bleof = false
		blbof = false
		bladding = false
		set objconn = server.createobject("ADODB.Connection")
		set objrs = server.createobject("ADODB.Recordset")
	end sub
	Public Sub Connect(database_name)
		strconn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath(database_name) & ";"
		objconn.open strconn
		blopen = 1
	End Sub
	public sub Open(table_name)
		if blopen = 0 then
			response.write "You must connect to a database first!"
			response.end
		elseif blopen = 2 then
			response.write "A table is already open!"
			response.end
		elseif blopen = 1 then
			objrs.open table_name, objconn, 3, 3
			if objrs.eof = true then
				bleof = true
			elseif objbof = true then
				blbof = true
			end if
			blopen = 2
		end if
	end sub
	public sub Close()
		if blopen = 0 then
			response.write "You must connect to a Database first!"
			response.end
		elseif blopen = 1 then
			response.write "You must open a table first!"
			response.end
		elseif blopen = 2 then
			objrs.close
			objconn.close
			blopen = 0
		end if
	end sub
	public sub MoveFirst()
		if blopen = 0 then
			response.write "You must connect to a database first!"
			response.end
		elseif blopen = 1 then
			response.write "You must open a table first!"
		elseif blopen = 2 then
			objrs.MoveFirst
		end if
	end sub
	public sub MoveLast()
		if blopen = 0 then
			response.write "You must connect to a database first!"
			response.end
		elseif blopen = 1 then
			response.write "You must open a table first"
			response.end
		elseif blopen = 2 then
			objrs.MoveLast
		end if
	end sub
	public sub MoveNext()
		if blopen = 0 then
			response.write "You must connect to a database first!"
			response.end
		elseif blopen = 1 then
			response.write "You must open a table first!"
			response.end
		elseif blopen = 2 then
			if objrs.eof then
				bleof = true
			else
				objrs.MoveNext
				if objrs.eof = true then bleof = true
			end if
		end if
	end sub
	public property get EOF()
		EOF = bleof
	end property
	public property get BOF()
		BOF = blbof
	end property
	public sub MovePrevious()
		if blopen = 0 then
			response.write "You must connect to a database first!"
			response.end
		elseif blopen = 1 then
			response.write "You must open a table first!"
			response.end
		elseif blopen = 2 then
			if objrs.bof = true then
				blbof = true
			else
				objrs.MovePrevious
				if objrs.bof = true then blbof = true
			end if
		end if
	end sub
	public property let field(field_name, strvalue)
		objrs.fields(field_name) = strvalue
	end property
	public property get field(field_name)
		field = objrs.fields(field_name)
	end property
	public sub AddNew()
		if blopen = 0 then
			response.write "You must connect to a database first!"
			response.end
		elseif blopen = 1 then
			response.write "You must open a table first!"
			response.end
		elseif blopen = 2 then
			objrs.addnew
			bladding = true
		end if
	end sub
	public sub Save()
		if blopen = 0 then
			response.write "You must connect to a database first!"
			response.end
		elseif blopen = 1 then
			response.write "You must open a table first!"
			response.end
		elseif blopen = 2 then
			if bladding = false then
				response.write "You must add a record first!"
				respone.end
			else
				objrs.update
				bladding = false
			end if
		end if
	end sub
	private sub Class_Terminate
		if blopen = 1 then
			objconn.close
		elseif blopen = 2 then
			objrs.close
			objconn.close
		end if
		set objrs = nothing
		set objconn = nothing
	end sub
end class
%>


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.