• MS Access – SQL Tutorial

    Among my many projects, lately I have been doing a fair amount of database development with SQL server and MS Access.  And I’ve written a tutorial on how to leverage the power of SQL server stored procedures through a MS Access database.  Here is a brief intro and a link to a full PDF of the article.  Comments welcome!

    Microsoft Access and Microsoft Server go together like a peanut butter and jelly sandwich.  Both offer unique strengths, and used together provide both a robust, secure data environment and a full featured design environment for client applications.  In this article I will walk you through the process of running parameterized stored procedures in a SQL database from an Access client application.  This allows us to take advantage of the security and speed of running database procedures in SQL server, while feeding local values based upon actions taken in our client Access application.

    Inspired by a recent article by Garry Robinson,  this tutorial builds an application that maintains a table to log client use of forms and reports in a MS Access database.  The routines write to a table in a SQL database using a stored procedure.  They pass parameters to this stored procedure (object name, object type, application name) from the client application.  So let’s get started!

    Tutorial PDF

    code_file

    Related Posts

    Tags: , , , , , , , , , ,
  • Author: Randy

    In my day job I serve as Information Technology Director for the Yale School of Drama. Otherwise I garden, play guitar, build stuff out of wood, take photos, play around with technology and have been blogging since 2003.

    Share on: LinkedIn

    Stay Informed!

    Did you enjoy this post? Then subscribe to my email newsletter and have the daily posts delivered directly to your inbox. Enter your email address here:

    Comments / 4 COMMENTS

    The majority of my development is MSAccess frontends to SQLServer data. Instead of Stored Procedures, I typically build SQL Strings and then use “CurrentProject.Connection.Execute strSQL” to do appends/updates. I typically have forms bound to only one record and generally have some means of passing the SQL Select * from tblSource Where PrimaryKey=X to the Recordsource property of the form. I have never had a performance complaint and have many times wondered why go to the hassle of stored procedures? Am I missing something? Thanks…

    Tracy Smith added these pithy words on Aug 21 08 at 8:25 am

    Tracy,

    One of the cool things about design work is how different people can arrive at different solutions to the same problems. For simple inserts or updates similar to what I put forward in the article there is probably little difference in the two approaches. But Stored Procedures can employ more complex logic, such as the whole BEGIN TRANSACTION – COMMIT – ROLLBACK type of thing — or conditional statements. There may also be an advantage from a security standpoint to keep the logic off the client, and on the server where it is less likely to be seen.

    I’m just beginning to discover the power of stored procedures myself, so I’m sure there are other points to consider as well. Thanks for the comment!

    Randall added these pithy words on Aug 21 08 at 8:45 am

    Thanks for the quick feedback!

    I also use the Begin Trans/Commit/Rollback when it applies. For example…

    Set cnn = CurrentProject.Connection
    cnn.BeginTrans
    booInTrans = True
    ‘ Create Inventory Component for Production Information
    strSQL = “Insert Into tblInventory (Fld1,Fld2, …) Values (Val1,Val2,…)
    cnn.Execute strSQL
    ‘ Add Activity Log
    strSQL = “Insert Into tblActivityLog (Fld1,Fld2,…) Values (Val1,Val2,…)
    cnn.Execute strSQL
    cnn.CommitTrans
    booInTrans = False

    exit_function:
    cnn.Close
    Exit Function

    err_function:
    If booInTrans Then
    cnn.RollbackTrans
    Resume exit_function
    Else
    MsgBox Err.Number & “-” & Err.Description
    Resume exit_function
    End If

    Tracy Smith added these pithy words on Aug 21 08 at 9:07 am

    ADD YOUR COMMENT
    Comments are moderated.

Welcome to RodeWorks

Randall Rode's online home for thoughts, notes, and experiments with a wide range of technology topics. Visit the about page for info on my recent projects and professional background. I welcome your comments!

  • Recent Comments

  • Coming Soon

    Learning Drupal

    March 15, 2010

    Easy path to installing a local copy of Drupal

    March 15, 2010

    Harnessing Social Media for campus communication

    March 15, 2010

    Site Topics