Discussion Locked

Combo Box using Access2000

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am creating a form using Access2000, my problem is I have a table called Postcodes and it has 2 fields Town and Postcodes.

what I would like in my form is when I select town(combo box)in my form field I would like the corresponding postcode toappear in the postcode field in my form.

Can some one help me please....

Thank you

Manjeet

9 replies

by donq

I do this often by basing my Form's Data Source on a dynaset query that deliveres every value for any record I need (including Town and Postcode). I then populate the "Town" field from a Combo box that has its "Row Source" property set to an SQL statement that delivers all of my form query options and its related Postcode. I then set the Postcode field on the form so it does NOT receive focus and instruct the combo boxes After Update event to requery the form.

Hope this helps - the secret is basing everything on queries that can be executed dynamically (or on-the-fly).

by richtee

A simple way to resolve your problem would be to change the ?postcode? field on your Form from a Text box to a Combo box. (in design view, right click, change to, select combo box). This will also eliminate the need for the special combo to make the selection.

In Properties:
Data Tab:
Set the Row Source Type to : Table/Query
Set the Row Source to: Select he table containing the town and postcodes from the drop down
Set Bound Column to: 1 or 2 depending which field is the postcode
Format Tab:
Set Column Count to: 2 (This will show both fields in your drop down)

Hope this helps. You can contact me if you need some more info on how to do this.

Rich

by bob sellman

Set the source for the combo box to select the town and the postcode. Set the displayed column widths for the combo box to 1" (or whatever is appropriate for the town) and 0" (1";0"), unless you also want to display the postcode with the town.

For the After update property of the combo box, include the following code:

me.Postcode = me.cboTown.column(1)

This will put the postcode value from the selected row in the combo drop down list into the postcode field. (Note that the column numbers start at 0 for this statement, even though on the properties you would refer to this column as column 2!)

You might also set the locked property of the postcode to true so the user could not change it.

If the correct postcode is not displayed when you go to a different record, set the on current property of the form to include the following code:

me.cboTown.requery
me.cboPostcode = me.cboTown.Column(1)

This discussion is closed to new replies.