How do I automatically populate fields?

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

Guest

I am trying to eliminate too much data entry from my forms.

How can I auto populate other fields in my form, when the user selects a particular combo box in the same form?

Is this possible?

Salgro
 
Salgro said:
I am trying to eliminate too much data entry from my forms.

How can I auto populate other fields in my form, when the user selects a
particular combo box in the same form?
Is this possible?

Yes, but first you should be positive that you even want to do this. Generally
copying data from one table to another is a no-no except for key values to
create the relationship links. This would not apply to time or record sensitive
data.

For example; on an Order form I need to enter the CustomerID on the order and I
might want to *see* other fields from the Customer table on my order, but if
they are not time or order-sensitive I don't want to copy them I just want to
look them up and display them. The stores address is an example of data you
should NOT copy. That way if the customer's address changes in the Customer
table you don't end up with bad data in the Orders table.

On the other hand if there were a field in the Customers table that indicated
their current discount rate, that would be data that I would want to copy to the
order because if I look at an order six months later I need to see the discount
"at the time the order was placed" not the current value (if it has changed).

Once you've made the above distinction the two methods are fairly similar. You
can have a ComboBox for entering the CustomerID (in my example) and include in
the ComboBox all the additional fields from the Customer table that you need the
data for. You can set the column widths for these to zero so they don't
actually display in the list.

Then to display fields you don't want to copy create unbound TextBoxes with
ControlSource properties similar to...
=ComboBoxName.Column(1)
=ComboBoxName.Column(2)
etc..

For fields you DO want to copy have bound controls that you populate in the
AfterUpdate event of the ComboBox.

Me.TextBox1 = Me.ComboBoxName.Column(1)
Me.TextBox2 = Me.ComboBoxName.Column(2)
etc..

ComboBox columns are zero-indexed so Column(1) is actually the second column.
 
Back
Top