vba queries giving old data because previous transactions still in process

  • Thread starter David via AccessMonster.com
  • Start date
D

David via AccessMonster.com

I have a Sales Order form with a continuous forms view subform (Sales Order
Line Item) in it, which contains the line item data for each order. I have
a line number counter on each line which corresponds to part of the primary
key of the salesorderlineitem table (the pk is made up of two fields:
salesordernumber and salesorderlineitemnumber). Anyway, when a user
creates a new order and starts typing in data in the first line, I have
code (in the Form_BeforeInsert event handler) which determines what the
next line number should be. This works great if the user is going along
slowly (normal speed), but if the user attempts to create two lines
consecutively very fast (like leaving blank space for comments on the
order, etc), the code occasionally creates two lines with the same line
number, which creates a Primary Key error when the database tries to save
the record. Is there any way around this type of thing? In general, is
there a way to make sure that any pending transactions on the fields that
you need to work with are complete before running queries on them? I have
experienced quite a few issues related to this for which I have had to come
up with annoying work arounds...

I would like to be able to somehow have the system wait until relevant
database transactions are complete before continuing in many cases. For
example, if a user purchases an item that they need for a Sales Order, and
the system creates a Purchase Order and the line in that PO with the item
they need to purchase, I would like to be able to wait to display the form
and subform until I know that the transactions are complete. As it is I
have overcome this problem with a fairly annoying workaround, but it
results in a flickering screen as it is continually refreshing waiting for
data. Another example of this issue is a "master form" that contains
listboxes that display related database objects, and when one of those
objects is created or deleted, sometimes those lists are not correctly
refreshed because those transactions have not been completed at the time of
the refresh commands. This also requires the "flickering screen" solution,
as far as I know.

If anyone knows any cool techniques that would help me out, I would really
appreciate it. It would make my system a lot more robust. Thanks!

-David
 
Top