Using Postcodes from Australia Post to automatically enter into

G

Georgina

Australia Post enables you to download a list of all towns with their
corresponding postcode.
I would like to be able use this so that I can start typing the name of the
town and access will:
Finish typing the name (because it recognises the name); and
Enter the corresponding postcode into another field.

This prevents any incorrect spelling of towns and incorrect postcode.

I have looked everywhere for hints on how to do this...thought there may be
someone who's already done it and can let me in on their secret!

Many thanks
 
J

John Vinson

Australia Post enables you to download a list of all towns with their
corresponding postcode.
I would like to be able use this so that I can start typing the name of the
town and access will:
Finish typing the name (because it recognises the name); and
Enter the corresponding postcode into another field.

This prevents any incorrect spelling of towns and incorrect postcode.

I have looked everywhere for hints on how to do this...thought there may be
someone who's already done it and can let me in on their secret!

Many thanks

I'd suggest basing a Combo Box on a query:

SELECT TownName, PostCode
FROM <this table>
ORDER BY TownName;

If there are fewer than 65536 towns in Oz, this should work. Leave its
AutoComplete property true (so it will expand to Alice Springs when
you have typed Alic).

In its AfterUpdate event put code to "push" the postcode:

Private Sub cboTowns_AfterUpdate()
Me!txtPostCode = Me!cboTowns.Column(1)
End Sub

It's (1) because the Column property is zero based.

One question though: surely big cities have multiple postcodes?

John W. Vinson[MVP]
 
G

Georgina

Thanks so much John.

Yes big cities would have multiple postcodes....I guess I would need a drop
down box or something.

will try what you have suggested first and see how I go. Thanks again,
you've been a great help.

Georgina
 
T

Tom Wickerath

Hi Georgina,

Depending on the size of your list, you could use a combo box, as long as
your list is not several thousand entries long. If you set the Auto Expand
property to Yes, the combo box will find the value as you type in the
characters.

An example is shown in the Northwind.mdb sample database. Open the Orders
form, and attempt to type in "B" and the list will find "Boston Crab Meat".
This example also shows you how to populate a textbox. It uses the DLookup
function to look up the Unit Price from the Products table. The use of domain
aggregrate functions (DLookup) is fine for single-user database, where the
data is on the local hard drive, but these functions can cause bottlenecks
when used in a multi-user database where the shared data is stored on a file
server.

There are other ways of doing this as well, without having to resort to
using a domain aggregrate function (DLookup). One method is to simply
include the postcode in the SQL statement that serves as the Row Source for
the combo box. So, for instance, you could use a statement similar to this:

SELECT CityID, City, PostCode FROM MyTable ORDER BY City, PostCode;

Set the combo box for (3) columns, but don't display the first one (CityID)
since this is the primary key. You may or may not want to display the
PostCode in the combo box. Displaying it will help to pick the correct one,
in the event that a city has more than one PostCode assigned. You can use the
Column Width's property to suppress displaying a column by setting it's width
to 0. So, for instance, if you decide to hide the postcode in the combo box,
you could set the following column widths:

0;1.5;0

This would make the second column selected in the SQL statement, City, 1.5"
in width. The first and the third columns would have zero width. Then, in the
After_Update event procedure for this combo box, instead of using the piggy
DLookup function, you could simply set the PostCode textbox as follows:

Private Sub cboCity_AfterUpdate()
On Error Goto ProcError

Me!txtPostCode = Me!cboCity.Column(2)

We use Column(2) to refer to the third column, since the columns are "zero
based" when using VBA code, ie. the first column selected, CityID, is
Column(0), the second column selected, City, is Column(1), and so forth.

If your list is very long, then you can use the idea shown in this
article--scroll to the topic titled "Combo and list box controls" to limit
the list to those towns that match the first two characters that you enter:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacbk02/html/ODC_CookbookCha pter8.asp


Tom
________________________________________

:

Australia Post enables you to download a list of all towns with their
corresponding postcode.
I would like to be able use this so that I can start typing the name of the
town and access will:
Finish typing the name (because it recognises the name); and
Enter the corresponding postcode into another field.

This prevents any incorrect spelling of towns and incorrect postcode.

I have looked everywhere for hints on how to do this...thought there may be
someone who's already done it and can let me in on their secret!

Many thanks
 
G

Georgina

Thanks for your reply Tom - very helpful!

Tom Wickerath said:
Hi Georgina,

Depending on the size of your list, you could use a combo box, as long as
your list is not several thousand entries long. If you set the Auto Expand
property to Yes, the combo box will find the value as you type in the
characters.

An example is shown in the Northwind.mdb sample database. Open the Orders
form, and attempt to type in "B" and the list will find "Boston Crab Meat".
This example also shows you how to populate a textbox. It uses the DLookup
function to look up the Unit Price from the Products table. The use of domain
aggregrate functions (DLookup) is fine for single-user database, where the
data is on the local hard drive, but these functions can cause bottlenecks
when used in a multi-user database where the shared data is stored on a file
server.

There are other ways of doing this as well, without having to resort to
using a domain aggregrate function (DLookup). One method is to simply
include the postcode in the SQL statement that serves as the Row Source for
the combo box. So, for instance, you could use a statement similar to this:

SELECT CityID, City, PostCode FROM MyTable ORDER BY City, PostCode;

Set the combo box for (3) columns, but don't display the first one (CityID)
since this is the primary key. You may or may not want to display the
PostCode in the combo box. Displaying it will help to pick the correct one,
in the event that a city has more than one PostCode assigned. You can use the
Column Width's property to suppress displaying a column by setting it's width
to 0. So, for instance, if you decide to hide the postcode in the combo box,
you could set the following column widths:

0;1.5;0

This would make the second column selected in the SQL statement, City, 1.5"
in width. The first and the third columns would have zero width. Then, in the
After_Update event procedure for this combo box, instead of using the piggy
DLookup function, you could simply set the PostCode textbox as follows:

Private Sub cboCity_AfterUpdate()
On Error Goto ProcError

Me!txtPostCode = Me!cboCity.Column(2)

We use Column(2) to refer to the third column, since the columns are "zero
based" when using VBA code, ie. the first column selected, CityID, is
Column(0), the second column selected, City, is Column(1), and so forth.

If your list is very long, then you can use the idea shown in this
article--scroll to the topic titled "Combo and list box controls" to limit
the list to those towns that match the first two characters that you enter:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnacbk02/html/ODC_CookbookCha pter8.asp


Tom
________________________________________

:

Australia Post enables you to download a list of all towns with their
corresponding postcode.
I would like to be able use this so that I can start typing the name of the
town and access will:
Finish typing the name (because it recognises the name); and
Enter the corresponding postcode into another field.

This prevents any incorrect spelling of towns and incorrect postcode.

I have looked everywhere for hints on how to do this...thought there may be
someone who's already done it and can let me in on their secret!

Many thanks
 
T

Tom Wickerath

You're welcome. Good luck with your project!

And thanks for marking my reply as an answer. This is appreciated.

Tom
_____________________________________
 
A

Allen Browne

Georgina, take a look at this article:
http://allenbrowne.com/ser-32.html

Because there are around 10k places in the AusPost list, the article
explains how to load the combo with matching place on the 3rd keystroke.
This means the combo never has more than a few hundred places loaded, so it
is lightning quick to load and manage, but it still auto-completes the place
names and assigns the postcodes.

One of the issues with Aus. place names is that there is not a one-to-one
correspondence between postcodes and place names. Some postcodes cover
several place names, and some places have multiple postcodes. So it does
come down to providing a short list for the user to select from.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top