Discussion Locked

Access Recordsets

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Most of the examples of recordsets relate to
looping through a subset of records. I am new at
Access VB and want to create a data entry form
using a recordset so I dont have to bind the controls
to the table, so I can do some validation beforecommitting the record. How do I begin, and how do I edit / move through records.

7 replies

by bob sellman

I've used an alternate method that permits easy entry, verification, and other work before commiting changes.

Create a copy of your source table (Source) layout (no data), I'll call it SourceInput. Be sure to turn off any autonumber columns and all indexes/keys.

Set your add/edit form to use this table. Bind your controls to the columns in the table. Include a "Save" button on your form. If you are in the Add mode for the form, perform your validation as appropriate and if everything's OK, then append the data to Source table. (Be sure not to append any autonumber columns, since they will automatically be numbered in Source.)

In order to edit a record, on your form that displays (no editing, adding, or deleting) the records in Source, include a button for "Edit record" (in addition to a button for "Add new record"). When the button is clicked, append the currently display record (using the primary key to select it) to SourceInput, then open the editing/add form. After the changes are made by the user and you've verified them, because you are in the edit mode the "Save" button will replace all data in the appropriate record in Source with the data in SourceInput.

After each Save on the input form, delete the record in SourceInput. You can also include a message asking the user if he wants to add anther record.

Note that the table SourceInput should be set up in the front end (application) Access97 database. It should not be a table in the back end database (i.e., the one containing all of the data tables that you link the front end to).

by estackpo

The technique of using an second add/edit form and table occurred to me as a way of also doing data validation. However I would really like to see the technique that would not require that and do the record navigation / add / edit on the single formwith one recordset

by camcc591

You should be able to do what is described in answer 1 above only without the auxiliary table - SourceInput. Create text boxes in your edit form but do not bind the data source to anything. Give the text boxes unique names, for example txtAddress for a text box that corresponds to the Address field in your Source table. When you are done with your validation checking, write the text box value to the corresponding table field the same way the fields in SourceInput would be written to the table.

Everything else would be the same as described above. To edit a record, copy the field values into the corresponding text boxes, edit, validate, then write the text box values back to the corresponding fields.

This whole process is very combersome because you must code many of the automatic features that Access normally provides. This includes the next and previous record arrow buttons, first and last record buttons, and record number display. But I have done it, it will work. Definately a challenge if you are new to VB.

by camcc591

You may be able to do this all in one recordset as you describe. You could use the Before Update event of the form to validate your data entry before writing the data to the single recordset. Use the form event so you can enter the entire recordset data before testing for validation. This should still allow the form's add, edit, and other automatic features to be used. I have not tried this myself to work out all the bugs or validate that it is possible. But it might work.

by estackpo

This is actually the way I have been doing things and is not the info I was looking for. Thanks for the suggestions.

This discussion is closed to new replies.