473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Creating and using Stored Procedures and Views in Jet

Perhaps many of you MS Access fanatics already know this, but it seems
that stored procedures and views are possible in Jet. I thought I
would leave this message just in case it would help anyone.

I discovered this the other day while doing some experiments with ADO
and ADO.NET. Basically, I wanted to run a stored MS Access query with
parameters using the syntax

Execute MyProcedure @Param1, @Param2...

I knew that I could run a stored Access query by creating ADODB
parameters, assigning values and executing as if I were running a
stored procedure. However, the above Execute syntax above also worked
perfectly to my surprise.

I later ran the code below from a Module in a simple Access database
with one table called Ranges with two columns (Range_ID integer,
Range_No varchar(50)). I expected to see the procedure prTest appear
in my list of queries, but it didn't--however it did appear in my
msysObjects table as type 5, which I think is for queries. I was able
to create, execute and drop the procedure as if I were working in SQL
Server.

I also tried creating a view, and did so with success. I was able to
create a ADO recordset by selecting from the view, which worked
perfectly as shown in the code below. Just like the procedure, the
view didn't show up in my list of stored queries, but it did appear in
msysobjects as type 5.

For me, this simply means that I can use ADO/ADO.NET to interact with
Jet databases in very much the same way that I do with SQL Server
databases.

I'm almost tempted to see if I can create a user-defined function in
Jet, but I'll save that for later.

Bill E.
Hollywood, FL

___________________________________
Sub TestProcedure()
Dim strSQL As String
Dim objConn As ADODB.Connection
Dim rst As ADODB.Recordset

strSQL = "CREATE PROCEDURE prTest ([@intRange_ID] integer) AS
SELECT Range_No FROM Ranges WHERE Range_ID=[@intRange_ID]"

Set objConn = CurrentProject.Connection

'Create a procedure
objConn.Execute strSQL

'Run the procedure
Set rst = New ADODB.Recordset
strSQL = "EXECUTE prTest 1"

With rst
..ActiveConnection = objConn
..CursorType = adOpenStatic
..Open strSQL
Debug.Print .Fields("Range_No")
..Close
End With

Set rst = Nothing

'Drop the procedure
strSQL = "DROP PROCEDURE prTest"
objConn.Execute strSQL

Set objConn = Nothing

End Sub

Sub TestView()
Dim strSQL As String
Dim objConn As ADODB.Connection
Dim rst As ADODB.Recordset

strSQL = "CREATE VIEW vwTest AS SELECT Range_No FROM Ranges"
Set objConn = CurrentProject.Connection

'Create a view
objConn.Execute strSQL

'Create a recordset based on the view
Set rst = New ADODB.Recordset
strSQL = "SELECT * FROM vwTest"

With rst
..ActiveConnection = objConn
..CursorType = adOpenStatic
..Open strSQL
Debug.Print .RecordCount
..Close
End With

Set rst = Nothing

'Drop the view
strSQL = "DROP VIEW vwTest"
objConn.Execute strSQL

Set objConn = Nothing

End Sub

Nov 13 '05 #1
0 2542

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dim St Thomas | last post by:
I am a developer working on a database client program. I am testing this program on a Windows XP machine (1.5 GHz AMD chip, 480 Mb RAM, 60 Gb disk) This machine has Oracle 9.2.0.1.0 and RedBrick...
11
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the...
5
by: gilles27 | last post by:
I've ready many of the posts on this and other newsgroups in which people describe working practices for source control of database scripts. We are looking to implement something similar in my...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
1
by: Matt Alanzo | last post by:
On another newsgroup an Access knowledgable party posted: >You should be able to connect an Access ADP to an existing SQLExpress >database running in SQLS 2000 compatibility mode. The only thing...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
5
by: BillCo | last post by:
I've encountered a problem while using ADO to save query objects. Union queries created normally (via the interface) appear in adox catelog.procedures rather than catelog.views. This is reasonably...
15
by: Wes Groleau | last post by:
When I try to import from Access, the DTS wizard only allows me to import tables and queries. OK, I'm not surprised the "macros" and reports don't come over. But it executes each query, and...
2
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.