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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate a Subform from a Combo Box 2

Status
Not open for further replies.

paulnnosh

MIS
Mar 25, 2004
32
Hi,

I have a table called Accounts and a table called Contacts. There are many contacts for each account so I would like a combo box with the Account names (selected from the Account Table) to populate a subform.

All the data to be viewed is to be read only.

I have created a form created an unbound combo box with a Row Source selecting all the Accounts on the Account table.

I have inserted a subform and I have set the Record Source of the subfor to be
SELECT Contacts.Account, Contacts.ContactName, Contacts.ContactTel, Contacts.ContactMob, Contacts.ContactEmail FROM Contacts
WHERE (((Contacts.Account)=Forms!Contacts!cboAccount));

This appears to be OK for the first entry but the data in the sub form does not change when I change the value in the combo box.

What am I doing wrong?

Thanks
 
In your combobox's after update event place this line of code:

me.YourSubformName.requery

Change the "YourSubformName" to the name of your subform.

HTH,
Eric
 
Thanks

I did that and now when I change the entry in the combo box I get an error message "Microsoft Access can't find the macro 'me'"

Do I need to set a Macro up?

Many Thanks
 
No that should work just fine the way it is. Go to your combo box properties. On the events tab locate "After Update". Clear anything out that you have put there. Click the ellipsis to the right. Select Code Builder. This will bring up the visual basic editor. Paste the code between the two "Private Sub..." line and the "End Sub" line.

HTH,
Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top