DLookup doesn't work in Subform (2000)

Re: DLookup doesn't work in Subform (2000)

You must use the name of the subform as a control on the main form. This is not necessarily the same as the name of the subform in the database window. To find the control name, open the main form in design view and click once on the subform to select it. Don't click on it a second time, for that will select something within the subform. The name of the subform will be displayed in the title bar of the Properties window, and also in the Name property. Use this name instead of frmSub.

Note: in the first expression, the main form is frmMaster2, and in the second expression, it is frmMaster. Make sure that you use the correct name.

Re: DLookup doesn't work in Subform (2000)

Hi Hans,
The subform control name is "frmsub". I used the same name as the subform in the database window. Because I couldn't get it to work in the a subform, I created frmMaster2 just to test the DLookup to see if it worked in the main form which it did. I've checked the names and they appear to be correct. Here's a cut & paste of the actual code:

Re: DLookup doesn't work in Subform (2000)

The DropDownDesc is a text field and your suggestion seems to have worked. I will now incorporate it into the real application.

Out of curiousity though... why does adding Chr(34) make the difference and why can you refer to the LivestockUtiliz1 field using Me. I thought you had to specify the parent form as well as the subform when refering to fields in a subform.

Re: DLookup doesn't work in Subform (2000)

Your code is the After Update event for a control on the subform. In its own module, you can refer to a form or report as Me. This is much easier than invoking Forms!..., since you don't need to specify the name of the form. Code with Me will still work if you rename the form, and it doesn't matter whether the form running the code is a main form or a subform or a sub-subform.

In the code I posted, I took the value of LivestockUtiliz1 out of the quoted string, instead concatenated "[DropDownDesc] = " with the value of LivestockUtiliz1. Text values, however, must be enclosed in quotes, and that is what the Chr(34) provide.

Re: DLookup doesn't work in Subform (2000)

I get it! When I was testing the DLookup, I changed the criteria to "DropDownDesc = 'Beef' " because I knew that was what the value of LivestockUtiliz1 should be. That did work for me and the correct value was returned. So the Chr(34) is basically doing the same thing. That makes sense.