The follow is a compendium of Access routines, each separated into its own database. Each database illustrates one or more possible solutions to a single problem. They are not intended to be fully functioning utilities, but rather an illustration of how the problem might be solved and are therefore intended for educational use. These routines are entirely free. You may use them anywhere and in any way you choose, with or without citation. Therefore, you agree to use them at your own risk. There is no warranty implied and I am not responsible for any damages that might result from their use.

Note: Files designated "Access 2000 DAO" use the DAO data model and require a reference to DAO set in Access versions 2000 and 2002 (XP). Files designated "Access 2000 ADO" do not require this reference, but may need a reference to ADOX set. Files designated "Access 2000" do not use a data model.

If you don't understand the above, or are having problems with User Defined Variables, Click Here

BoilerPlate2.mdb ( intermediate )This sample is a useful template for an application. It is mostly the same as Boilerplate.mdb but with a different MainDataEntry Form.

Books.mdb ( intermediate ) "Books.mdb" and it's companion database "Books_be.mdb", make up a simple personal book inventory database. It uses the "BoilerPlate.mdb" sample to create a complete application.

TrainingRegistration.mdb ( intermediate )This sample is a general purpose training registration database. It is a complete application which demonstrates many of the features of the other sample databases.

Automation

AppendValuesToExcel.mdbThis sample demonstrates how to append data from a database to an Excel spreadsheet using Office Automation to find the next empty row in the spreadsheet.

ExportToExcel.mdb ( intermediate ) This sample demonstrates how to export data from a database using the TransferSpreadsheet method, but have the data populate a formatted spreadsheet. The trick here is to export the data to a NEW tab in the Excel workbook and link the fields from the new tab into the formatted spreadsheet.

ExportToExcelCharts.mdb ( intermediate )Sample with Documentation. This sample demonstrates how to export data from a database using the TransferSpreadsheet method, but have the data populate a Chart. The trick here is to export the data to a NEW tab in the Excel workbook and link the fields from the new tab into the chart.

CSVtoFixed.mdb ( intermediate ) This sample reads a CSV file and exports it as a fixed width file. Module 1 (CSVtoFixed) does the entire process in code. For very large records, Module 2 (CSVtoFixed2) uses a table to allow you to create your own Export Spec.

NormalizeDenormalize.mdb ( intermediate ) It illustrates how to take a table which has fields like Value1, Value2, Value3,... and writes them into a table which has one field (Value) with each of the values in a new record rather than having them all in one record.

This sample demonstrates how to normalize a simple PC_Inventory table. Its purpose is to demonstrate the general principles of normalizing denormalized data from a spreadsheet.

NormalizingRepeatedColumns2 (beginner)Document IncludedThis sample demonstrates how to normalize a PC_Inventory table that has two sets of repeated columns. It's purpose is to demonstrate the general principles of normalizing denormalized data from a spreadsheet.

NormalizingRepeatedColumns3 (beginner)Document IncludedThis sample demonstrates how to normalize a table that has repeated Yes/N0 columns. It's purpose is to demonstrate the general principles of normalizing denormalized data from a spreadsheet.

This sample demonstrates how to normalize a table that has repeated columns with VBA. It's purpose is to demonstrate the general principles of normalizing denormalized data from a spreadsheet with code rather than SQL statements.

RoundingStuff.mdb ( beginner )This sample shows a variety of rounding techniques, the most common being rounding to the nearest x decimal places. The function RoundIt is similar to the Round function in VB. All the code is stored in the basRounding module.

DateStuff.mdb ( intermediate )This example illustrates how to do a variety of date calculations like: First day of Month, Last Day of Month, First Day of Next Month, First Day of Current Week, Last Day of Current Week, First Day of Current Work Week, Last Day of Current Work Week.

YearsMonthsDays.mdb ( intermediate )A variety of functions created by different developer's to calculate the difference between two dates, which can also be used for Age Calculations. Some work in some situations and not in others. You'll have to decide which is best.

ChangingColorFields.mdb ( Access 97 Only)This sample illustrates how to change the color of a control on a form based on information in the form. In this case, if Check 14 checkbox is checked then the values of Desc will be red, otherwise it will be blue. Access 97 ONLY. For higher versions (Access 2000+) see my sample ConditionalFormatting.mdb.

ConditionalFormatting.mdb ( beginner )This sample illustrates how to change the color of a control on a form based on information in the form. In this case, if Check 14 checkbox is checked then the values of Desc will be red, otherwise it will be blue. This does not work with Access 97 and earlier. For those, see my sample ChangingColorFields.mdb.

ImproveFormPerformance.mdb ( intermediate )One way to improve the performance of a form that is bound to a LARGE dataset is to split the data into smaller chunks. This form uses the "Phonebook" method to do that. Click one of the 27 buttons at the top and the form will show you only those records in the table that start with the corresponding letter.

ListBoxSetTableValue.mdb ( intermediate ) This sample illustrates how to use a list box to update a "Selected" field in a table and also read which items are selected in the table and set those list box items to True.

ListboxSubform.mdb ( intermediate )This sample illustrates use a list box to simulate a simple subform. The user can either double-click the listbox or click the edit button. Then a popup form appears which allows him to select multiple values. These values are written to a separate tab.

OrderListBox.mdb ( intermediate )This sample shows how to make a listbox reorder by clicking on the column header. It also shows how to use the same button to sort ASC or DESC

"Other"Problem.mdb ( advanced )This example shows one method of handling the situation where the user wants a combo box to pick from, but also wants to have an "Other" category where they can add free-text qualifying the "Other".

ReallyBadDesignDecisions.doc ( beginner )Document with Sample Databases. Case study of a really bad database design based on the assumption that the paper form should determine the database design. This ZIP file contains two databases: "ReallyBadDatabase.mdb" and "ReallyBadDatabaseReborn.mdb".

RecordNavigation.mdb ( intermediate )This form illustrates how to exactly duplicate the actions of the default record navigation buttons including the RecordNumber Of TotalRecords feature.

SubForm3Levels.mdb ( advanced )Access does not allow more than two levels of subforms. At times, however, your data model indicates the need for more levels. This is one way to implement a third level through the use of a list box.

Unbound.mdb ( intermediate )This form illustrates how to use UNBOUND controls to add, delete, and edit records in a table using the DAO add/edit/update methods.

UnboundSQL.mdb ( intermediate )This form illustrates how to use UNBOUND controls to add, delete, and edit records in a table using SQL statements, rather than the DAO add/edit/update methods.

Import/Export/Update

CreateTableFromLinked.mdb ( intermediate )This sample illustrates how to create a native Access 2000 table from a linked Excel table. This process can be easily modified to do the same thing for linked Text or ODBC tables.

3) Modify the code to loop through a table of table and file names (MyExport)

Look in the "basExport_TransferSpreadsheet" module for the relevant code.

ImportHTML.mdb ( intermediate )This sample illustrates how to use the LineInput statement to import text from a text file in an extremely unconventional format. The file is an HTML file, and the code searchs for the HTML tags to find specific information and puts that in a field.

ImportLineInput.mdb ( intermediate )This sample illustrates how to use the LineInput statement to import text from a text file with a mixed format. Each line of the file is a separate record, but is delimited in a variety of ways.

ImportSpreadsheet.mdb ( intermediate )This sample illustrates 3 things: 1) How to back up a database using the Compact Method, 2) Create a native Access 2000 table from a linked Excel table 3) Import data to an existing table.

SeekWithLinkedTable.mdb ( intermediate ) It is usually said that the Seek method cannot be used with a linked table. This is true, it cannot. However, it WILL work if you open the table in the remote database explicitly with the OpenDatabase method. This sample illustrates how to do this.

SQLDAOLoader.mdb ( advanced ) This sample shows how to modify the structure of a Back-End database using SQL DDL (data definition language) statements and DAO code. This sample does much the same as "SQLLoader.mdb", but does not require text files to hold the SQL.

SQLLoader.mdb ( advanced )This sample shows how to modify the structure of a Back-End database using SQL DDL (data definition language) statements. The actual code is found in the Back-end database (SQLLoaderBE.mdb).

DataEntryMask.mdb ( beginner ) This sample illustrates a way to restrict what kind of characters are input into a textbox without using an input mask. This method checks the characters as they are typed and only allows legal characters.

ERMaster.pptNot an Access sample, but a useful Powerpoint template for creating ER Diagrams.

FlatFileDemo.mdb ( beginner )This example illustrates some of the difficulties inherent in bad (non-normalized) database design and how they can be corrected. It is not a formal tutorial on Normalization, rather it is a series of examples which allow you to demonstrate the kind of trouble that a non-normalized can produce. I use this example in my classes as an introduction to why you would want to normalize a database design.

Pictures.mdb ( beginner )It is usually preferable NOT to store OLE objects like pictures in the table itself. It causes massive database bloat. The usual solution is to store the pictures as files on the hard drive and store the file name in the table.

Snapshot.mdb (beginner)It is usually preferable NOT to store OLE objects like snapshots in the table itself. It causes massive database bloat. The usual solution is to store the snapshots as files on the hard drive and store the file name in the table. This sample demonstrates how to to this.

This sample illustrates how to create a query which displays the BeginDate and EndDate of a range based on a single EffectiveDate stored in the table. It is assumed that the Effective Date range of a record spans the time from the Effective date of the current record and the Effective Date of the NEXT record (minus 1). There are three methods shown here: Using a 1) correlated subquery, 2) DMax domain aggregate function, and 3) LEFT OUTER JOIN.

ChooseQueryFromList.zipThis sample shows how to display all the queries in your database in a listbox and run them with a button.

CreateQueries4.mdb ( advanced )This form illustrates how to create a relatively flexible inter-active query facility for an end-user. It allows you to choose the table, then shows the fields available for that table and then values available for the fields.

CreateQueries5.mdb ( advanced ) This set of samples illustrate how to create a flexible query generator for your users. It is similar to CreateQueries4.mdb, but no longer limits the query to 3 criteria.

CreateQueryFields.mdb ( intermediate )This sample illustrates how to programmatically create a query based on a table or another query and select only those fields that you want to see. It also has a form, which shows how to restrict the rows based on a criteria.

This sample (with full documentation) illustrates how to do a variety of DDL (Data Definition Language) operations using both SQL and DAO. DDL operations are those that modify the database structure, ie. tables, fields, indexes, and relationships.

DaysBetweenQuery.mdb ( beginner )This sample illustrates how to create a "Days Between" query, that is, display the difference between dates in subsquent records of a table.

MaxQueryProblem.mdb ( beginner ) The Problem: You want to create a query which will return a MAX Date and the corresponding Amount, grouping them on the Customer Name.

PreviousDateQuery.mdb (beginner)This sample illustrates how to create a Previous Date query. It shows how to: 1) Display the previous date in subsquent records of a table or 2) Display the previous date in subsquent records of a table over a group.

RecreateTableInSQL.mdb ( advanced )This sample will read the table structure of the table selected in the listbox and programmatically build a series SQL statements to recreate the table and all indexes. The SQL Statements are saved in a script file with a .sql extension.

ChooseReportFields.mdb ( intermediate ) This sample very roughly illustrates how to create a query programmatically which chooses the FIELDS to be reported on a report based on the selected values of a multi-select list box.

ChooseReportFieldsRows.mdb ( advanced )This sample very roughly illustrates how to create a query programmatically which chooses the FIELDS to be reported on a report based on the selected values of a multi-select list box and then allows the user to specify the ROWS to be reported.

ChooseReportFromList3.mdb ( intermediate )This sample shows an alternate way to open reports with a parameter form. It allows the user to select either a report directly or a form in which they can choose a parameter for the report.

CrossTabReport.mdb ( intermediate )The problem with crosstab queries has always been that if you try to make a report based on one, you inevitably have problems with field names when the crosstab changes. This sample demonstrates how you can get around this problem.

Greenbar.mdb ( beginner )This sample illustrates how to make your report a "greenbar" report, that is one that has alternating lines of color. Check behind the individual reports for the relevant code.

HasContinued.mdb ( intermediate )This example illustrates two methods of how to work around the 'HasContinued' bug, so that you can get a 'Continued' status for group headers within a report.

BackUpWithCompact.mdb ( intermediate )This sample illustrates how to back up a database using the Compact Method. It creates a backup file called "BackUpWithCompact2kXX_XX_XXXX.mdb" with the X's representing the data. It puts this file in the same directory as the database.

ChooseReportFields.mdb ( intermediate ) This sample very roughly illustrates how to create a query programmatically which chooses the FIELDS to be reported on a report based on the selected values of a multi-select list box.

ChooseReportFieldsRows.mdb ( advanced )This sample very roughly illustrates how to create a query programmatically which chooses the FIELDS to be reported on a report based on the selected values of a multi-select list box and then allows the user to specify the ROWS to be reported.

ChooseReportFromList3.mdb ( intermediate )This sample shows an alternate way to open reports with a parameter form. It allows the user to select either a report directly or a form in which they can choose a parameter for the report.

CompactDatabase.mdb ( advanced ) This sample illustrates how to compact the current database programmatically. It assumes that the tables reside locally. (To compact a Back-end database, see my sample "CompactBackEndDB.mdb".)

DeleteTablesAtStart.mdb ( beginner ) This sample illustrates how to delete ImportError tables at start up. For illustration purposes, the RunMacro button executes the code, but if you rename the macro to AutoExec, it will run each time the database opens.

UpsizeTable2SQLServer.doc ( intermediate )Document with sample database. This sample reads the table definition of an Access table and makes a CREATE TABLE statement in T-SQL that will recreate the table in SQL Server.

Zip97.mdb ( intermediate )This sample was created before the advent of WinZip in an attempt to automate the compression process. It uses a DOS version of PKZIP an Zip2Exe. It will also create an self-extracting zip file.

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot delete your posts in this forumYou cannot edit your posts in this forumYou cannot create polls in this forumYou cannot vote in polls in this forum