I have a form designed as an invoice. i have a text box which gets is value
(customerID) from the previous form which is still open in the background.
Control source for CustomerID contains =Forms![Select Customer]![customer ID]
what i want is for my invoice form to carry on doing what its doing but also
to store the customer ID into a table. Any Ideas
I'd suggest a different approach, actually two different approaches.
The easy way is to not open a separate form at all. Instead, make this
Invoice form a Subform of the Customer form. That way you don't have
to worry about transferring any data at all; the subform software
takes care of it automatically.
If you have good reasons not to do this, you'll need a bit of VBA
code. The most reliable way would be to pass the CustomerID in the
OpenArgs argument of the OpenForm command in the first form. I presume
you have a command button to open the invoice form from the customer
form; edit the button's Click event to include a line like
DoCmd.OpenForm strDocName, <arguments>, OpenArgs:=Me![Customer ID]
Then in the Invoice form's Open event put code like
Private Sub Form_Open(Cancel as Integer)
If Len(Me.OpenArgs & "") > 0 Then
Me!CustomerID.DefaultValue = Chr(34) & Me.OpenArgs & Chr(34)
End If
End Sub
This will pass the value from the field or control named [Customer ID]
(which, by the way, I'd suggest renaming to CustomerID; blanks in
fieldnames can become a hassle) into the Default property of the new
form's CustomerID field, so new invoices will fill it in
automatically.
John W. Vinson[MVP]