How can I avoid creating extra empty records in an input form?

XV1957

Registered User.
Local time
Today, 16:47
Joined
Aug 6, 2014
Messages
80
Please help. I always have a problem with input forms in Access in that I usually end up with an empty excess record which is being created because I do not know how to program this correctly.

I have a Purchase Order Receipt form (frmPurchase). When I receive a certain quantity of an article associated with a lot number (or a serial number) I have another input form opening up (frmLotorSerial), passing to it through Openargs, the article and the quantity received.

Say we receive 10 units of which we want to register the serial number, I want the user to be able to enter a maximum of 10 units (could be 10 records if each record = 1 serial number, but it could be less than 10 if we have several units per lot number), and not one more, into this frmLotorSerial.
The record looks like this:
- key
- artno (article)
- recqty (quantity received)
- date
- warehouse
- lot number

I used the lost_focus event on lot number to check whether the total received quantity in this form matches the total passed to it from the Purchase form, and if it does to stop the input. Since I could not close the window in the code of this event (error 2585) I moved the close command to the current event of the form.
Doing this closes the form all right, but it always creates one record extra, which of course does not carry any information, apart from the date which has a default value of now.

How should I program/what events should I use to:
- test that the user should not go any further (total received in frmLotorSerial = total received in frmPurchase)
- close the window and, above all, not create this extra record.
Thanks a lot for your help.
 
Only one note: Normally the after update event is used for checking!
Show the code you've for closing the form, it doesn't sound correct it is creating a record. The date default, is set as in the control's property "Default" or do you put it in by code?
 
Hello JHB,
just gotten back from a trip abroad, which is why my reply is late.
Thanks a lot for your reply.
My problem was that when I reached the right number of records processed, I tried to leave the form, but there was always an extra record created.
I think I now solved the issue by setting 'me.allowadditions = false' when the right number of records has been saved. Do you think this is the way to go?
Having taught myself Access, with a lot of help from this Forum, I sometimes feel I am missing some essentials. But by and large, I am progressing rather well, my small ERP is moving forward.
Thanks again.
 

Users who are viewing this thread

Back
Top Bottom