Form to add details to subform

garywood84

Registered User.
Local time
Today, 20:28
Joined
Apr 12, 2006
Messages
168
I'm building an order entry system. tblOrders contains one record for every order, and lines within each order are stored in tblOrderDetails, related to tblOrders by the OrderID.

I've created a form to allow order entry (frmOrders). The form is based on tblOrders, and displays related records from tblOrderDetails in a subform.

I don't want users to add items to orders by typing them into this subform, so have set it to not allow additions. Instead, I want there to be a button above the subform which says "Add Line". This should bring up a form (frmAddOrderLine) on which the user can enter the line they want to add, and when then click OK, they'll see the original form again, with a new line in the order.

I've created all the required forms, but when frmAddOrderLine is opened, from the button on frmOrders, the OrderID field is blank - where this needs to be the OrderID from the active record on frmOrders. Can anyone tell me how I can do this?

Thanks,

Gary
 
Forms!frmAddOrderLine.OrderID = Me.OrderID
 
Paul,

Thanks for this. I've not got that aspect working.

Just to complicate things a little bit more, I want to have two buttons on frmAddOrderLine, one of which is "Cancel". When this is clicked, the new record which has been created should be deleted, and the form closed down.

The trouble is that some of the fields on my form are required, so my attempts so far to create a cancel button have failed, because if these two fields are empty, I get an error when the cancel button is clicked. Can you suggest any code that would work?

Cheers,

Gary
 
I think there's enough going on here that a sample db would be a big help.
 
Paul,

Thanks for your reply. I'm attaching a quick sample I've thrown together. There's only one table and form, but it should illustrate the point.

The form would only be used for new data entry. Half way through filling in the form (or after entering just one field), the user might want to cancel. The "Cancel" button therefore needs to delete the partially completed record and close the form.

There's no code behind the Cancel button at the moment. I tried putting code that deleted the current record and then closed the form, and this worked, if the whole form had been completed. However, if not all of the fields on the form had been completed, I got an error when the button was clicked to say that data was required in some fields (as set by the required property in the table) - even though if the Cancel button's code were to run, that data would be deleted anyway!

I hope this makes more sense, but please let me know if anything isn't clear. Many thanks in advance for your help.

Gary
 

Attachments

I realise you may still be thinking about it/working on it, but has anyone got any ideas on this?

Cheers,

Gary
 
Sorry, we went out to dinner about the time you posted, and I never saw this. Does this do what you want?

Me.Undo
DoCmd.Close

I filled out all the fields and clicked it, and it did not add a record.
 
Paul,

Sorry, we went out to dinner about the time you posted, and I never saw this.
LOL - don't worry - it was 2.15am here, so I went to bed after posting!

Thanks for the code; it works perfectly. I don't know what I'd do without this forum!

Cheers,

Gary
 

Users who are viewing this thread

Back
Top Bottom