One cool thing I've done in the past is utilized stored queries to minimize code. These are similar to stored procedures if you utilize Oracle. You basically create a common sql statement in access, then call that in your vb app (ASP in my case) with the parameters required for the stored query. Here's an example of what I've done.... keep in mind it is for an ASP webpage, but should be similar for VB.
Code:
*****************************************************
<%
' -- InsertProc.asp --
%>
<html>
<head>
<title>Running Stored Procedures in Access Database (Insert Value)</title>
<style>p { font-family:verdana,arial; font-size:10pt; font-weight:bold; }</style>
</head>
<body><p>
<%
' Connection String
Dim connStr
connStr = "DRIVER=Microsoft Access Driver (*.mdb);DBQ="
connStr = connStr & Server.MapPath("StoredProc.mdb") & ";PWD=Whateveryourpasswordis"
' Connection Object
Dim con
Set con = Server.CreateObject("ADODB.Connection")
' Recordset Object
Dim rs
' connecting to database
con.Open connStr
Here we execute the insertproc query
' executing stored procedure
Set rs = con.Execute ("exec InsertProc XXX") ' XXX is the data passed to the stored query
Now run another stored query called SelectProc
Set rs = con.Execute ("exec SelectProc")
' showing all records %>
The code below just writes the table data to the web page
<table border="1" width="25%">
<%for each x in rs.Fields ' Write the field names in the table headers
response.write("<th>" & x.name & "</th>")
next%>
</tr>
<%do until rs.EOF ' Read thru each record %>
<tr>
<%for each x in rs.Fields ' Put the value of each field of the current record into the table
Response.Write "<td>" & (x.value) & "</td>"
next
rs.MoveNext ' Move to the next record %>
</tr>
<%loop
' Close connections and release the objects in memory
con.Close
Set rs = Nothing
Set con = Nothing
%>
</p></body>
</html>
*************************************************
The access query is named InsertProc. And the query code looks like this....
Code:
INSERT INTO [Names] ( Name )
VALUES ([@newName]);
This simple query inserts the value you pass into Table Names into Field Name.
The code for the SelectProc is this....
Code:
SELECT *
FROM [Names];
Anyway.... Thought this could be handy for others.
Bookmarks