#Name error when refernecing a sub-form field (1 Viewer)

sandracwalsh

New member
Local time
Today, 18:21
Joined
Nov 18, 2011
Messages
4
Hello -

I am going crazy trying to sort out what should be a very straightforward reference to a field on a sub-form. There is an error in the WHERE clause of my query but I can't figure it out.

The hierarchy of my data is as follows:

Trips -> Activities -> Contacts

I have a main form called f_MainTripForm. On this Main form I have a sub-form called f_ActivityDetails where the user selects the Company they are visiting from a drop-down named Company_DD with a control source of Company_Listing_ID

The f_ActivityDetails sub-form has a tab control in which I have a sub-sub form named f_OtherFirmContacts on one of the pages

f_MainTripForm
-> f_ActivityDetails joined on Trip_ID
->-> f_OtherFirmContacts joined on Activity_ID


In f_OtherFirmContacts I have a dropdown named SelectContact_DD that should select only the contacts that have a Company_ID = to the Listing_ID stored in the Company_DD drop-down in f_ActivityDetails.


I have this code for the SelectContact_DD drop down:

SELECT
q_ContactsAtACompany.Cont_LISTING_ID,
q_ContactsAtACompany.DISPLAY_NM,
q_ContactsAtACompany.POSITION_NM,
q_ContactsAtACompany.COMPANY_ID

FROM
q_ContactsAtACompany

WHERE (((q_ContactsAtACompany.COMPANY_ID)=[Forms]![f_MainTripForm]![f_ActivityDetails].[Form]![Company_DD]))

ORDER BY
q_ContactsAtACompany.DISPLAY_NM;

When I open the form, I get a request to Enter Parameter Value.

When I create an unbound field in f_Contacts with the Control Source
=[Forms]![f_MainTripForm]![f_ActivityDetails].[Form]![Company_DD]

I get a #Name error.

When I manually enter the COMPANY_ID in the Parameter Value request, all works fine.

Thanks for any suggestions - I am sure it is something simple to do with the syntax of the WHERE clause.

Sandra
 
Last edited:

vbaInet

AWF VIP
Local time
Today, 23:21
Joined
Jan 22, 2010
Messages
26,374
The problem is that the subform loads before its parent form. So in your case, f_OtherFirmContacts loads before f_ActivityDetails, hence the pop-up because it can't find the form referenced.
 

sandracwalsh

New member
Local time
Today, 18:21
Joined
Nov 18, 2011
Messages
4
Thank you - I will need to figure out the form load sequence issue.


I still think there is an issue with the WHERE statement because when I remove the drop down, I dont get the the Enter Parameter Value error, but the unbound field that has Control Source

=[Forms]![f_MainTripForm]![f_ActivityDetails].[Form]![Company_DD]

still gives me a #NAME error.

Any ideas?
 

vbaInet

AWF VIP
Local time
Today, 23:21
Joined
Jan 22, 2010
Messages
26,374
* Make sure the name of your subform control is not the same as the subform
* Then, use the Expression Builder to locate the field
 

sandracwalsh

New member
Local time
Today, 18:21
Joined
Nov 18, 2011
Messages
4
Thanks again, VB -

I had just dragged my subforms onto the parent forms without creating a SubForm control, which means that the Name and the SourceObject had the same name.

Now that the SubForm controls are set up properly, everything works perfectly!
 

sandracwalsh

New member
Local time
Today, 18:21
Joined
Nov 18, 2011
Messages
4
Darn - I spoke too soon. Everything was working properly so I saved and re-opened my form and I am back to square one.

The Control Source of the unbound field within the f_ActivityDetails subform is now

=[Forms]![f_MainTripForm]![f_ActivityDetails_SFC].[Form]![Company_DD]

f_ActivityDetails is the Source Object within the f_ActivityDetails_SFC subform control.

f_OtherFirmContacts is the Source Object within the f_OtherFirmContacts_SFC subform control.

Thanks for any insight.
Sandra
 

vbaInet

AWF VIP
Local time
Today, 23:21
Joined
Jan 22, 2010
Messages
26,374
Ok, so what is the name of the subform and what is the name of the subform control? This goes back to my last post.

Are you sure the control being referenced is actually showing a value? Is it calculated?
 

Users who are viewing this thread

Top Bottom