mhmaid said:
thank you dirk for help
i am entering expense transactions thru my form "expense reports" i
receive invoices batches(each batch contains many invoices) and have
to make record for each invoice.what i want is when i finish entering
invoices for one batch and checked records for accuracy, to lock
those transactions only to prevent edition or deletion .other
transactions should be locked only after checking them.
It seems to me that you would have two tables (primarily) involved here:
an InvoiceBatches table, with one record per batch, and a related table
of BatchInvoices, with one record per invoice, each record stamped with
the BatchID (or equivalent key) of the batch it belongs to. The tables
would be in a one-to-many relationship. Of course, you could call these
tables by other names that make sense to you.
Then you would enter and edit these data via a main form/subform
arrangement. The main form would be based on the InvoiceBatches table,
and the subform would be based on the BatchInvoices table nd linked to
the main form by the BatchID field.
The InvoiceBatches table would have a field defined to indicate that
data entry for this batch has been completed and verified. This field
might be a simple Yes/No field represented on the form by a check box,
or it might be a date/time field that your code would manipulate such
that, if the field isn't Null, it contains the date and time on which
the batch was completed and validated. Either way, this field can be
tested in code to see if this batch is complete and should be locked.
You would then have code in the main form's Current event that does
something like the following:
'----- start of example code -----
Private Sub Form_Current()
Dim blnEditable As Boolean
If Me!chkBatchComplete Then
blnEditable = False
Else
blnEditable = True
End If
Me.AllowEdits = blnEditable
Me.AllowDeletions = blnEditable
End Sub
'----- end of example code -----
Note two things about the above code:
1. It locks both the main form and the subform.
2. All controls on these forms become uneditable -- even unbound
controls. If you need a mechanism to unlock the form after you've
locked it, you can put a command button on the form to do it.
Whatever mechanism you use to mark a batch as being complete and
verified, you'll want that mechanism to include code that either calls
the Form_Current event procedure after marking the record, or else locks
the form directly.