Creating a look up field

  • Thread starter Thread starter Smithpr Bears
  • Start date Start date
S

Smithpr Bears

I have a file with post code data and want to be able to enter the name of
the town and have the correct post code displayed in a field.
 
The easiest way is to setup the combo's RowSource property to include not
nly the town name, but also the postcode, and then simply extract the
postcode when the town is selected.

Set the combo's Rowsource to:
SELECT TownName, Postcode
FROM tblPostcodes
ORDER BY TownName

Set the combo's ColumnCount property = 2
Set the combo's ColumnWidths property = "3cm;1cm" 'or as appropriate

Then add the following code:
Private Sub cboTownName_AfterUpdate()
If Not IsNull(me!cboTownName) Then
Me!txtPostcode = Nz(Me!cboTownName.Column(1), 0)
End If
End Sub

By the way, if the postcodes are listed in another database, link the table
in which they're stored.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Back
Top