Autofill details in a Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

First off, I'm a complete novice who has been landed with the job of building
a Database. Heres my latest problem.

I have a Form used to enter order info into a table that will be used to
plan production.
I would like to have the details of the Product ordered to autofill, once
the unique Customer Code & Product Code have been entered into the form (both
these fields are the primary key on the source table).
Any suggestions would be great as I am running out of hair to pull out.
 
A common approach would be to select the Customer and Product codes from
combo boxes. You'd also have additional information about each customer and
each product in the RowSource, so that in the AfterUpdate event of the combo
box, you'd populate the appropriate text boxes by referring to the data for
the selected row, using the Column collection.

For example, if you had Customer Name as the 2nd column and Customer Address
as the 3rd column of cboCustomer, your AfterUpdate event would be something
like:

Private Sub cboCustomer_AfterUpdate()

Me.txtCustomerName = Me.cboCustomer.Column(1)
Me.txtCustomerAddress = Me.cboCustomer.Column(2)

End Sub

(Note that the Column collection starts counting at 0, not 1)

Another approach would be to do lookups in the related tables in the
AfterUpdate event of whatever controls you use to accept Customer Code and
Product Code.
 
If this form is also used to navigate between records, and not only for data
input, then you should put this code in the OnCurrent event of the form.

Or, instead of writing code, you can add to the control source of the text
boxes the reference to the combo.
For example, to add the name to the txtCustomerName then in the control
source you can write
= [cboCustomer].Column(1)
 
Hello Doug,

I tried your suggesstion but the text box is not changing/populating for me.
All I want to do is select a part number from a combo box and I want a text
box to automatically display the part name.
What am I missing?

Option Compare Database

Private Sub Part_Number_AfterUpdate()
Me.Text4 = Me.Part_Number.Column(2)
End Sub

Thanks.
 
Douglas, I don't know if this is appropriate or not, but your responce was
the first I've found in two days of looking that made this task easy enough
for me to do it. This was the final stage of me completing my database. THANK
YOU!
 
Back
Top