Providing you with plenty of sample MS Access VB code and other database goodies.

Beware of scope when adding items to Collection objects

When adding items to a Collection object, remember not to add something

The following code will add a particular field's value from an ADODB.RecordSet object to a Collection. However, the scope of the RecordSet object is only within this function. After it completes, each item within the Collection object will have a null value.

Public Function GetPeriods() As Collection
Dim rs As ADODB.Recordset
Dim col As Collection

Set rs = New ADODB.Recordset
Set col = New Collection

The WRONG way to clear a table

I swear, I haven't seen something this stupid in a very long time (and I work with Access everyday).

DoCmd.OpenTable "TblOracleUploadAdjs", acViewNormal, acEdit
DoCmd.RunCommand acCmdSelectAllRecords
DoCmd.RunCommand acCmdDelete
DoCmd.Close acTable, "TblOracleUploadAdjs"

For the uninitiated, what this does is open a table up, select all the records, deletes them, then closes the table. The better way to do this would be to execute the following query:

delete from TblOracleUploadAdjs;

Or to fully solve this:

Boundary Checking for ADODB.RecordSet Objects

Not that this is a very elegant solution, but I needed to get rid of a bug in production. The cause of this was the check for one of the recordset's fields. After looping a second time and MoveNext() bringing the recordset to EOF, you couldn't check its values anymore. So to fix this I added the following line:

If Not rsUinvcat.EOF Then

This checks your boundary conditions before attempting to read a value that might not currently exist. Always check your bounds!


For i = 0 To intCols
If Not rsUinvcat.EOF Then

Common Database Problems

When coming into a business area, you as a dba may encounter numerous problems with your clients' databases. This is usually due to a lack of formal, in house knowledge. These may have been created for smaller tasks, but years later are now mission critical. Below are some common problems.

  • Table normalization - Lack of 3NF leads to update, insert, and delete anomalies.
  • Fixed width text fields too large - Datatype of char(255) where a smaller width or varchar should be used.

Working From Home? Setup a good work area first.

Working from home can be great. All you need is:

  • company laptop
  • VPN connection
  • worthless winter car (Mustang)
  • 2 really bad snowdays
  • Avoid Loops as Performance Killers

    Loops are a performance killer. They shouldn't be used when they don't have to. On the plus side, the run time of a standard loop is O(n) which is linear. Nevertheless, know your language and the functions available. It's a mistake to loop through a data structure when it has a built in function call to do what you need more efficiently. I learned this the hard way as you'll see.

    I was clearing a list box control in an Access form by removing each item from the list:

    'clear the listbox
    For i = lstAcct.ListCount - 1 To 0 Step -1
    lstAcct.RemoveItem i
    Next i

    Microsoft Access VB Code Samples, Articles, FAQs, and Database Development

    Feel free to use these examples for your own personal use.

    Syndicate content

    Warning: Access denied for user: 'dbo205616392@%' to database 'db205616392' query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Access denied for user: &amp;#039;dbo205616392@%&amp;#039; to database &amp;#039;db205616392&amp;#039;\nquery: INSERT INTO accesslog (title, path, url, hostname, uid, sid, timer, timestamp) values(&amp;#039;&amp;#039;, &amp;#039;node&amp;#039;, &amp;#039;&amp;#039;, &amp;#039;38.107.179.217&amp;#039;, 0, &amp;#039;45739f908ee7e0a75e57cac7c61b5b82&amp;#039;, 193, 1337549350)</em> in <em>/homepages/24/d90262255/htdocs/msaccess/includes/database.mysql.inc</em> on line <em>172</em>.', 2, '', 'http://www.msaccessresource.com/', '', '38.107.179.217', 1337549350) in /homepages/24/d90262255/htdocs/msaccess/includes/database.mysql.inc on line 172

    Warning: Access denied for user: 'dbo205616392@%' to database 'db205616392' query: INSERT INTO watchdog (uid, type, message, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '<em>Access denied for user: &amp;#039;dbo205616392@%&amp;#039; to database &amp;#039;db205616392&amp;#039;\nquery: INSERT INTO sessions (sid, uid, cache, hostname, session, timestamp) VALUES (&amp;#039;45739f908ee7e0a75e57cac7c61b5b82&amp;#039;, 0, 0, &amp;#039;38.107.179.217&amp;#039;, &amp;#039;messages|a:1:{s:5:\\&amp;quot;error\\&amp;quot;;a:1:{i:0;s:417:\\&amp;quot;user warning: Access denied for user: &amp;amp;#039;dbo205616392@%&amp;amp;#039; to database &amp;amp;#039;db205616392&amp;amp;#039;\\nquery: INSERT INTO accesslog (title, path, url, hostname, uid, sid, timer, timestamp) values(&amp;amp;#039;&amp;amp;#039;, &amp;amp;#039;node&amp;amp;#039;, &amp;amp;#039;&amp;amp;#039;, &amp; in /homepages/24/d90262255/htdocs/msaccess/includes/database.mysql.inc on line 172