FreeFour
First said:
I want to take the 2 keys that passed along
Where do these keys come from? Is the form open with the required info? We need to know this if we are to help. (I am assuming
will pick the name means that the this info is available on the calling form.
Second said:
fill in other unbounded text boxes for the Customer's first name and last name, address
Piece of cake.
Okay, here is an idea. I am going to assume that the combo box with the customer's name is called cmbCustomer, and the bound field for the cusomter is CustomerID.
Create a combo box on the Invoice form, dont use the wizard, and make it invisible. How? Form is open in design view, and the "Properties" window is open (from the menu, "View" -> "Properties". Click on the Combobox object tool and add it to the form. Cancel out of the wizard, and delete the lable. Click on the "Other" tab in the Properties and change the name to "cmbCustomer". Now click on the "Data" tab and change the value for the "Visible" field to "No".
I would suggest that you use this field to bind the CusomterNo to the Invoice table.
Now we want to create an event procedure for the OnCurrent event. Click on the square box for the form where the verticle and horizontal rulers meet in the top left corner. This selects the form. Click on "Events" in the Property window, and select the OnCurrent field. Choose the [Event Procedures" from the drop down box, and then click on the "..." button to the right of the field. This takes you to the VBA coding window.
You will see...
Code:
Private Sub Form_Current()
Sub
Add the following...
Code:
Dim strSQL as String, lngCustomerID as Long
'You will have to teak the following to match your form
'and field names
lngCustomerID = Nz([forms]![NameOfYourFirstForm]![cmbCustomer], 0)
If lngCustomer > 0 Then
strSQL = "Select CustomerID, CustomerLN, CustromerFN, Address FROM tblCustomer Where CustomerID = " & lngCusomterID
'Now load the combo box with one record for the customer
Me.cmbCusomter.RowSource = strSQL
Me.cmbCusomter.Requery
'You will define three text fields to match
'text box names on left side of equation
Me.CustomerLN = Me.cmbCusomter.Column(1)
Me.CustomerFN = Me.cmbCusomter.Column(2)
Me.Address = Me.cmbCusomter.Column(3)
Else
Msgbox "No customer selected", vbOKOnly
DoCmd.Close acForm, Me.Name, acSaveNo
End If
You will obviously have to tweak...
- associated form and field
- SQL statment to match your design
You mentioned "2 keys". I assume the other is the vehicle. But I don't know the purpose -- well I guess it would be to print the vehicle info on the form. A similar approach can be used.
By-the-way, another approach is to use DLookup. Here, you use one query to grab four fields. The other would require individual statements, and you would still need to bind the CustomerID to the Invoice record.
Richard