View Full Version : DLookUp


AdamH
04-24-2002, 08:32 AM
I created the following behind a field in a form DLookUp("[CMSRPhoneNumber]","[tbl:CM Sales Rep]","[CMSRName]='" & [frm:Main Table].[Combo134] & "'"). I have a table that contains two fields, Name and Phone Number. On a form, I have a combo box with a persons name listed from this table. I want to automatically populate the phone number into another field on this form. I can get the Dlookup to work in a Query but it will not work on the form. I put the expression in the BeforeUpdate section of the field. HELP!

Jack Cowley
04-24-2002, 08:57 AM
Create your combo so the name and phone number are in it. Assume name is the first column and phone the second. In the After Update event of the combo box use code like this:

Me.PhoneFieldOnForm = Me.ComboBoxName.Column(1)

David R
04-24-2002, 08:58 AM
Get rid of your Dlookup, it's inefficient and not needed here as long as there is a 1:1 ratio between name and phone number.

Add another column to your combo. Make the width 0" so you can't see it in the dropdown, but the data will be there. Then in your Phone Number box, make the record source =Combo134.Column(2)

(I think the column number is right, you might have to fiddle that part)

Lock the field so people don't try to modify it, and you're good to go. No code required.

P.S. Hi Jack!

[This message has been edited by David R (edited 04-24-2002).]

AdamH
04-24-2002, 09:23 AM
Worked beautifully!! YOU GUYS RULE - Thank you so much!!!!!