Automatically fill in customerID on Orders Subform

  • Thread starter Thread starter Darwood
  • Start date Start date
D

Darwood

How can I automatically fill in the CustomerID field on my Orders Subform?

The Orders Subform is linked and loaded by pressing a command button on the
Customers Form. The Orders Subform itself contains an Order Details subform
that is on the same form. Interestingly the Order Details, OrderID (foreign
key) field is automatically populated with the related OrderID and I would
like the same effect for the CustomerID (foreign key) field on the Orders
Subform.

All forms have been generated by wizards.

Tables are as below. Primary and Foreign Key in parenthesis:
Customers (CustomerID)
Orders (OrderID, CustomerID)
OrderDetails (OrderDetailsID, OrderID)

Many thanks,
 
Darwood said:
How can I automatically fill in the CustomerID field on my Orders Subform?

The Orders Subform is linked and loaded by pressing a command button on the
Customers Form. The Orders Subform itself contains an Order Details subform
that is on the same form. Interestingly the Order Details, OrderID (foreign
key) field is automatically populated with the related OrderID and I would
like the same effect for the CustomerID (foreign key) field on the Orders
Subform.

All forms have been generated by wizards.

Tables are as below. Primary and Foreign Key in parenthesis:
Customers (CustomerID)
Orders (OrderID, CustomerID)
OrderDetails (OrderDetailsID, OrderID)

If the Orders form is really a subform of the Customers form then you use the
MasterLink and ChildLink properties of the subform control to do this. If you
examine these properties on your OrderDetails subform control you will see how they
are set.
 
I'm having the same problem and know a lot less about
visual basick than you do. I am opening a form via a
button on the main form that should automatically link the
main and sub form via a client id, I'm using the button
wizard and it will only link the sub record if it already
has the client id in it it won't automatically fill in the
client ID on a blank form. I think that's the same
situation you were in. My problem is I don't know where
to put the code that you are specifying below.

Any help would be appreciated.

Eva
 
Eva said:
I'm having the same problem and know a lot less about
visual basick than you do. I am opening a form via a
button on the main form that should automatically link the
main and sub form via a client id, I'm using the button
wizard and it will only link the sub record if it already
has the client id in it it won't automatically fill in the
client ID on a blank form. I think that's the same
situation you were in. My problem is I don't know where
to put the code that you are specifying below.

First, you should stop using confusing terminology. A subform is a form embedded
inside another form. If you are pressing a command button on a form to open a
*separate* form, then it is not a subform.

Second, if you look at the code below, it tells you exactly "where it goes". It goes
into the form's code module in the sub-routine named "Form_BeforeInsert".

Find the Before Insert event property on the form's property sheet. In the drop down
list of selections choose "[Event Procedure]". Then click on the build button [...]
at the right of the property box. This should automatically take you to the code
window positioned between two lines of code that define the start and end of the
sub-routine. Just place your code lines in between those two and save.

Eva
-----Original Message-----
Ignore that.
The following code on the subform seems to have done the trick.

Private Sub Form_BeforeInsert(Cancel As Integer)
Forms![Orders Subform]!CustomerID.Value = Forms! [Customers
Orders]!CustomerID.Value
End Sub
 
Thank you,

I think even I can manage that :-)
Eva
-----Original Message-----


First, you should stop using confusing terminology. A subform is a form embedded
inside another form. If you are pressing a command button on a form to open a
*separate* form, then it is not a subform.

Second, if you look at the code below, it tells you
exactly "where it goes". It goes
into the form's code module in the sub-routine named "Form_BeforeInsert".

Find the Before Insert event property on the form's
property sheet. In the drop down
list of selections choose "[Event Procedure]". Then
click on the build button [...]
at the right of the property box. This should
automatically take you to the code
window positioned between two lines of code that define the start and end of the
sub-routine. Just place your code lines in between those two and save.

Eva
-----Original Message-----
Ignore that.
The following code on the subform seems to have done
the
trick.
Private Sub Form_BeforeInsert(Cancel As Integer)
Forms![Orders Subform]!CustomerID.Value = Forms! [Customers
Orders]!CustomerID.Value
End Sub


.
 
Back
Top