DatabaseLessons.com

'Serving the Microsoft® Access
Community since 1997'

News/Blog
Tables
Queries
Forms
Reports
Modules
Miscellaneous
Subscribe
Free Samples
Videos
Services
Links
About Us

 

 

Unbound Forms in MS Access - Part 3

In part 1 of this article we created a simple database, consisting of one table and one form. The form was an unbound form. The database showed one way of editing existing records using unbound text boxes. In part 2 we looked at a method for adding new records.

Here in part 3 of this series we will add a Clear button.

(article continues after sponsor spot)



If a user starts to add a new record or is editing an existing record, the Clear button will cancel what they are doing and reset everything.

This requires us to add another new button, which I will call cmdClear, with a caption of "&Clear". The VBA code in the button's OnClick event is shown below. This button's VBA code clears all the text boxes, clears the New Record flag, and puts the focus back to the list box.

Something else you should notice. We have started to do what all good programmers should start doing early in a project's life - use documentation in the code.

NOTE: All the VBA code segments on the Database Lessons site assume that you have DAO references active. If you are not sure what this means, and you are using Microsoft Access 2000 or higher, click here.

Code for cmdClear (OnClick event)

'--- clear all the text boxes and set the txtID to 0
'--- and the new flag to false
txtCompany = Null
txtContact = Null
txtAddress = Null
txtCity = Null
txtID = 0
chkNew = False
'--- set the focus to the list box
lstData.SetFocus

Further Suggestions:

What's next? Part 4 will look at forcing the user to follow proper procedures. As it stands, we can start to edit an existing record part way through an add procedure. A dangerous process.

If you would like the sample database that I created to test this series (Access 2000 version only) please visit this page. The sample database is stored in a 21K zip file, so you will need WinZip, or similar.

 
Note: This web site dedicated to MS Access database users is an independent publication of Richard W. Killey and is not affiliated with, nor has it been authorized, sponsored, or otherwise approved by Microsoft® Corporation.
 

 

© 2006, 2007, 2008 Richard W. Killey. All Rights Reserved. - Privacy Policy