Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DLookUp to populate a form field

Status
Not open for further replies.

Thurls

MIS
Joined
Jun 15, 2003
Messages
9
Location
AU
Hello all,

I'm new to this site so be kind, I use a form to poulate a table in Access 2000, in the form there is a field to input suburb then another to enter the post code for that suburb. I have a another table with all the suburbs and their post codes so I thought I could use DLookUp to populate the post code field.

I'm using a VB code on enter, like this

Private Sub Postcode_Enter()
Dim varX As Variant
varX = DLookup("[Pcode]", "T_Postcodes", "[Suburb1] = '" & Me![Suburb] & "'")
End Sub

but get a nothing in the postcode field, not getting an error message just no result. any ideas?

Cheers,

Cole
 
Your idea is a good one. You are just not executing this code at all. Put the following code in the forms OnCurrent event procedure and the AfterUpdate event procedure of the [Suburb] control.

Me![Post_Code] = DLookup("[Pcode]", "T_Postcodes", "[Suburb1] = '" & Me![Suburb] & "'")

This way everytime you move to a new record or someone updates the [suburb] control the DLookup will populate the control Me![Post_Code]. Change this control to the name of your forms control.


Bob Scriver

Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Thanks for your help, much appreciated, It works great.
I have lots to learn.

Cheers,

Cole
 
Great!! [2thumbsup]

Glad to be of help. As for having a lot to learn, we have all been there. One step at a time and pretty soon you will be answering questions here.

Bob Scriver

Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top