Skip to content
Access 2002/2003 VBA code examples

Introduction

This website is dedicated to collecting Access VBA code snippets. These were all tested with Access 2003, but are likely to work just as well with Access 2007 or Access 2010, with perhaps some minor adjustments. With the advent of faster and more reliable network infrastructure, and the possibility to not only use a file-based storage system, but Sharepoint and MS SQL Server as well, Access seems to have acquired a new lease on life. It certainly seems to be regaining popularity in the corporate world.

Contact me

Should you find errors, or have suggestions for improvements of anything you find on this web site, just drop me a line using the contact form. I am also available for Access or Drupal consulting assignments.

Determine uniqueness for rows in delimited file using defined key columns

This is a handy perl script if you're trying to import delimited data into a database table that has a unique constraint on one or more columns. The script takes the field and line(row) separator, and you can tell it which columns should make a unique key.

unique.pl:

if (!@ARGV) {
$scriptName = $1 if $0 =~ /.+\\(.+).pl/;
print STDERR "Usage: $scriptName separator c1:c2:...:cn \n";
# Example use: unique.pl SOH STX 0:2 T:\Temp\Rukkers\F804_121023.txt
exit;
}

$fieldseparator = shift @ARGV;
die "First parameter should be field separator" unless $fieldseparator;

Put a list of table names and field names into a combo or list box

If you want to write generic code that can act on multiple tables and/or fields, here's some handy helper functions that you can use to populate combo or list boxes with the names of all tables and all fields in a particular table. You can call the functions in either a form load event, or an after update event in a list or combo box to set the valuelist of the control you want to contain the function result.

Function listTables(bShowSys As Boolean) As String
Dim db As DAO.Database
Dim td As DAO.TableDefs
Dim result As String
Set db = CurrentDb()

AdaptiveThemes