C
CM
CM said:Hi Steve,
Tried this, but how do I ensure I keep the postcode typed in?? at the moment
the record source is set to the postcode from the main table. If I change
this to a combobox, would it lose this information?
Thanks for all your help!
I am interested to find a solution, as I could use the code for similar
things on other forms...
Cheers
Colin
fillPC Datasheet said:Colin,
Try this ----
Rather than put any code in the combobox's Afterupdate event, put the following
code in the combobox'x On Change event:
If Len(Me!MyCombobox) >= 3 Then
Me!Town = Me!MyCombobox.Column(1)
Me!County = Me!MyCombobox.Column(2)
End If
Nothing will happen when you enter the first two characters of the postcode.
When you enter the third character, Town and County will automatically fill with
the Town and County associated with the first postcode that begins with the
three characters that were entered. If the Town and County are not the ones you
want, enter a fourth character and Town and County will automaticallythatwith
the Town and County associated with the first postcode that begins with the four
characters that were entered. You can continue to enter characters for the
postcode and Town and Country will keep changing at each character.
Steve
PC Datasheetinwillcount
to 3 data!)allowbut=[Postcode]tono
avail.
I have made a table called "tbl-postcodes" which I have three fields,
first
one is "Postcode", then "Town" then "County"
I have tried the code listed underneath the original, but nothing seems
to
work.
Thanks for any help anyone can give me, on this!
Colin
************* Code Start **************
' This code was originally written by Erika Yoxall.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Erika Yoxall
'
Sub Zip_OnExit(Cancel As Integer)
Dim varState, varCity As Variant
varState = DLookup("State", "tblZipCode", "ZipCode =[Zip] ")
varCity = DLookup("City", "tblZipCode", "ZipCode =[Zip] ")
If (Not IsNull(varState)) Then Me![State] = varState
If (Not IsNull(varCity)) Then Me![City] = varCity
End Sub
'************* Code End **************
The code I have used is the following....
Sub MembersPostcodeTextBox_OnExit(Cancel As Integer)
Dim varCounty, varTown As Variant
varState = DLookup("County", "tbl-postcodes", "Postcode =[Postcode]
")
varCity = DLookup("City", "tbl-postcodes", "Postcode")If (Not IsNull(varCounty)) Then Me![County] = varCounty
If (Not IsNull(varTown)) Then Me![Town] = varTown
End Sub
My form contains the information from one table called "centralsystem"
and I
have made a table called "tbl-postcodes" which has the following sample
data
which I will finish off once I know it works
Field 1 is named Postcode
Field 2 is named Town
Field 3 is named County
In the rows it would be something like this...
SW1A 1AA Westminster London
PL1 1AA Plymouth Devon
BH1 1AA Bournemouth Dorset
However, when I try the postcodes in the form, I want it to
automatically
pick the town and county, which is a selection in a combo box. It
doesn't
save much time, I know but it all helps!
Thanks
Colin