entryfield linked to selectionlist

J

Jean-Paul

Hallo,
I created a form with a selectionlist of all belgian cities.
Next to this field I created an entryfield where the zip-codes should appear
What I want is this entryfield to show the zipcode when the up and
downarrow of the selectionfield is clicked


In the "after update" propertie of the selectionlist I wrote:

Dim db As Database
Dim tb As Recordset
Dim f As Form
Set db = CurrentDb()
Set tb = db.OpenRecordset("postnummers")
Set f = Forms![leerkrachten]
tb.MoveFirst
Do Until tb.EOF
If tb!gte = f!gem_lk Then
f!PN_lk = tb!PN
Exit Do
End If
tb.MoveNext
Loop

tb!gte citiy's name
PN is the zipcode

The zipcode only changes when I put the cursor in the selectionfield and
then move to the next entryfield with the tab button

What do I have to do?

Thank you all

JPentryfield l
 
N

n00b

You can't trap the events for the up and down button on a listbox.
You will need to create two buttons that can update the list
selection.

In the custom up button, place this in the click event:

selectionlist = selectionlist.ItemData(selectionlist.ListIndex - 1)

and the converse of this in the custom down button:

selectionlist = selectionlist.ItemData(selectionlist.ListIndex + 1)


These will not fire the after update event of the listbox, so you will
have to call after update explicity in your click events.

selectionlist = selectionlist.ItemData(selectionlist.ListIndex - 1)
selectionlist_AfterUpdate


The after update event of the listbox would need something like this:

PN_lk = selectionlist


I strongly suggest you learn how to use the Dlookup function to avoid
scrolling through complete recordsets. In your code, you scroll the
recordset to find the Zip Code. If the table you are scanning is
large, you will have really long delays. You could have done
something like this:

Me.PN_lk = Dlookup("PN", "postnummers", "gte ='" & Me.gem_lk & "'")
 

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

Similar Threads


Top