Add a record in subform w/o typing on parent form

xolo

Registered User.
Local time
Today, 20:55
Joined
May 6, 2009
Messages
34
How is it to add a record in the subform without typing anything on its parent form? In this case, the text boxes on the parent form will be automatically filled with their own default value once someone type in on the subform. Thanks!
 
Depends on the form/subform relationship and if its genertating a new record or searching for and exsiting one....
 
Depends on the form/subform relationship and if its genertating a new record or searching for and exsiting one....

Thank you for your response!
For instance, I have a simple purchase-order form with OrderId (AutoNumber), Date (DefaultValue=Date()) and UserId (DefaultValue is derived from another from) on the parent from. On the subform I have ProductId, and Qty. The subform is connected to the parent form by the OrderId. So, when I add a new purchase order, I want to type in only on the subform and the form will automatically be filled with the DefaultValues.
 
Last edited:
So you have a form with customer details and you want to say click a button that opens your purchase order and passes the cutome details to it and autofills the fields yes?

I would use an openargs procedure to do this something like this in the on click event of your first form:

DoCmd.OpenForm "frmWOTemp", , , , acAdd, acDialog, Me.CustomerID


Then in the On Load event of your Purchase Order form:

Dim strCustomerID As String

If Not IsNull(Me.OpenArgs) Then
'Allocate Openargs value to string
strCustomerID = (OpenArgs)
'Pass value of string to form control
Me![CustomerID] = strCustomerID

End If

Assuming your dafault date is set correctly this should work ok BUT as you are passing a Customer ID I assume the control on the purchase order form is a combo box with a lookup for the customer name? If not you may want to pass the Name of the Custome and not their ID....

Good luck John
 
Thanks John, but I am afraid that's not what I meant. Sorry I was not clear.

When I open the form, I want to type in directly on the subform to add new purchase order (new record on the parent form). But when I do that, the parent form is still blank (no record added on the parent form). To be more clear, please find the file in the attachment.

Thanks again,
Wiguna
 

Attachments

I can't open your DB because it is A2007.

Another type of approach which is what use is to have a form open which is based on the table that supports the subform and when the form opens (for a new record) the ID data from the main form record is inserted plus any defaults.

I do this for a couple of reasons. Firstly, it mush better for entering data than is the subform. Secondly, there a values going in the Many table that of displayed on all the subforms associated with the Many table. A third reason is I have subforms so there is no record selector, navigation buttons etc.

You could open the secondary form the subform although i do it from the main form.
 
I can't open your DB because it is A2007.

Another type of approach which is what use is to have a form open which is based on the table that supports the subform and when the form opens (for a new record) the ID data from the main form record is inserted plus any defaults.

I do this for a couple of reasons. Firstly, it mush better for entering data than is the subform. Secondly, there a values going in the Many table that of displayed on all the subforms associated with the Many table. A third reason is I have subforms so there is no record selector, navigation buttons etc.

You could open the secondary form the subform although i do it from the main form.

Thanks Mike375, that makes sense. I was then wondering after reading your response: maybe using "SendKeys" to the "main form" on the "AfterInsert" event of the Subform could also work? Attached is the DB file in A2003 version.
 

Attachments

What would you be using SendKeys for? You lost me:) But generally SendKeys would be only used as last resort.
 
I guess I made many people lost. :)

Anyway, I like to thank you and John for the time you have spent. This forum has made my knowledge better about Ms Access.

Cheers!
Wiguna
 
Xolo,

Old thread I know but did you find a solution to this? I am trying the same thing since if you enter something in the subform with no master it gets lost.

Thanks in advance.
Iain
 

Users who are viewing this thread

Back
Top Bottom