DAO 3.6 Library

RefreshSQL

Remember in the first Sub that we wrote we included a call to a sub called RefreshSQL. This is a very important procedure, it binds the database that you wish to you to variables that all of the procedures that we have written so far can use.

All of the code I have given you so far belongs in the module we created called modDatabase. You can add this to any project that you wish to add database capabilities to. To complete functionality though, this module relies on another sub, RefreshSQL. This is different depending on which data you wish to extract from the database and what your database contains. For this reason, RefreshSQL could be different in every project you write.

So by adding modDatabase to your project, you're only 80% of the way to adding database functionality. You should also include another module, which I usually call modDefaultDatabase, with unique code in dependant on the database you are manipulating.

This module should include:

  • Declarations of recordset variables.
  • A RefreshSQL procedure.

A sample modDefaultDatabase is below, showing you what I mean by the above:

Option Explicit

Global rstPeople As Recordset
Global rstAnimal As Recordset

Sub RefreshSQL()
   Dim strSQL As String

   strSQL = "SELECT * FROM [People]"
   Set rstPeople = db.OpenRecordset(strSQL)

   strSQL = "SELECT * FROM [Animals]"
   Set rstAnimals = db.OpenRecordset(strSQL)
End Sub


Make sure your RefreshSQL procedure binds ALL of your recordset variables to a recordset using SQL, as shown above. For a better understanding of SQL, see James Crowley's excellent article which can be found here.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“If debugging is the process of removing software bugs, then programming must be the process of putting them in.” - Edsger Dijkstra