| DatabaseLessons.com |
'Serving the Microsoft® Access |
|
|
Unbound Forms in MS Access - Part 1I have seen many postings in the newsgroups with questions about MS Access unbound forms.
I am not going to open a can of worms and answer the Why!!! (article continues after sponsor spot) I am going to write a series of articles about the How. At least, the way I see it. I have developed my own particular style of MS Access unbound forms. I like them because them give me TOTAL control over a process and make it impossible for the user to "accidentally" mess up data. In order to replace data or add new data the user MUST PURPOSELY click a button called SAVE. I realize that bound forms can be protected with various events. Just remember that I am not going to go into the details of why! Here is an example of my way of creating unbound forms.
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 lstData (AfterUpdate event) txtCompany = lstData.Column(1) Code for cmdSave (OnClick event) Dim rst As Recordset Set rst = CurrentDb.OpenRecordset("select * from tblCustomers where CustID=" & txtID) How it Works When you click on an entry in the listbox, the afterupdate event fires and the data from the listbox gets copied into the textboxes.Notice the use of the column(n) property of the listbox. If you change the data in one of the textboxes, you need to click the Save button. When you do, the OnClick event fires and I use recordset methods to find and update the record in the table. What's next? Part 2 of this article will add an Add New button. This adds a bit of a challenge. How does the Save button know whether it is an updated record (needing rst.Edit) or a new record (needing rst.AddNew)? Further Suggestions: I leave it to the reader to add some error protection. 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. |
|
|
© 2006, 2007, 2008 Richard W. Killey. All Rights Reserved. |